Because of its length, only the code for the function itself is shown on this page. The demo script that shows how to use this function is available as a separate download.
复制代码 代码如下:
Function ReadRegValue( myComputer, myRegPath, myRegValue ) ' This function reads a value from the registry of any WMI ' enabled computer. ' ' Arguments: ' myComputer a computer name or IP address, ' or a dot for the local computer ' myRegPath a full registry key path, e.g. ' HKEY_CLASSES_ROOT/.jpg or ' HKLM/SOFTWARE/Microsoft/DirectX ' myRegValue the value name to be queried, e.g. ' InstalledVersion or "" for default ' values ' ' The function returns an array with the following elements: ' ReadRegValue(0) the computer name (the first argument) ' ReadRegValue(1) the hive number (see const declarations) ' ReadRegValue(2) the key path without the hive ' ReadRegValue(3) the value name (the third argument) ' ReadRegValue(4) the error number: 0 means no error ' ReadRegValue(5) the data type of the result ' ReadRegValue(6) the actual data, or the first element of an ' array of data for REG_BINARY or REG_MULTI_SZ ' ' Written by Rob van der Woude ' http://www.robvanderwoude.com
Dim arrRegPath, arrResult(), arrValueNames, arrValueTypes Dim i, objReg, strHive, valRegError, valRegType, valRegVal
' Assume no error, for now valRegError = 0
' Split the registry path in a hive part ' and the rest, and check if that succeeded arrRegPath = Split( myRegPath, "/", 2 ) If IsArray( arrRegPath ) Then If UBound( arrRegPath ) <> 1 Then valRegError = 5 Else valRegError = 5 End If
' Convert the hive string to a hive number Select Case UCase( arrRegPath( 0 ) ) Case "HKCR", "HKEY_CLASSES_ROOT" strHive = HKEY_CLASSES_ROOT Case "HKCU", "HKEY_CURRENT_USER" strHive = HKEY_CURRENT_USER Case "HKLM", "HKEY_LOCAL_MACHINE" strHive = HKEY_LOCAL_MACHINE Case "HKU", "HKEY_USERS" strHive = HKEY_USERS Case "HKCC", "HKEY_CURRENT_CONFIG" strHive = HKEY_CURRENT_CONFIG Case "HKDD", "HKEY_DYN_DATA" strHive = HKEY_DYN_DATA Case Else valRegError = 5 End Select
' Abort if any error occurred, and return an error code If valRegError > 0 Then ReadRegValue = Array( myComputer, myRegPath, _ myRegPath, myRegValue, _ valRegError, "-", "-" ) Exit Function End If