Class std_registry Private Sub Class_Initialize() Set objRegistry = Nothing End Sub
' Connect to the reg provider for this registy object Public Function ConnectProvider32( sComputerName ) ConnectProvider32 = False Set objRegistry = Nothing 'On Error Resume Next Dim oLoc : Set oLoc = CreateObject("Wbemscripting.SWbemLocator") Dim oCtx : Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet") ' Force 64 Bit Registry Call oCtx.Add("__ProviderArchitecture", 32 ) Call oCtx.Add("__RequiredArchitecture", True) Dim oSvc : Set oSvc = oLoc.ConnectServer(sComputerName,"root/default","","",,,WBEM_MAX_WAIT,oCtx) Set objRegistry = oSvc.Get("StdRegProv") If Err.Number = 0 Then ConnectProvider32 = True End If End Function
' Connect to the reg provider for this registy object Public Function ConnectProvider64( sComputerName ) ConnectProvider64 = False Set objRegistry = Nothing On Error Resume Next Dim oLoc : Set oLoc = CreateObject("Wbemscripting.SWbemLocator") Dim oCtx : Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet") ' Force 64 Bit Registry Call oCtx.Add("__ProviderArchitecture", 64 ) Call oCtx.Add("__RequiredArchitecture", True) Dim oSvc : Set oSvc = oLoc.ConnectServer(sComputerName,"root/default","","",,,WBEM_MAX_WAIT,oCtx) Set objRegistry = oSvc.Get("StdRegProv") If Err.Number = 0 Then ConnectProvider64 = True End If End Function
Public Function IsValid() IsValid = Eval( Not objRegistry Is Nothing ) End Function
' Used to read values from the registry, Returns 0 for success, all else is error ' ByRef data contains the registry value if the functions returns success ' The constants can be used for the sRootKey value: ' HKEY_LOCAL_MACHINE ' HKEY_CURRENT_USER ' HKEY_CLASSES_ROOT ' HKEY_USERS ' HKEY_CURRENT_CONFIG ' HKEY_DYN_DATA ' The constants can be used for the sType value: ' REG_SZ ' REG_MULTI_SZ ' REG_EXPAND_SZ ' REG_BINARY ' REG_DWORD Public Function ReadValue(ByVal hkRoot , ByVal nType , ByVal sKeyPath, ByVal sValueName , ByRef Data) On Error Resume Next ReadValue = -1 Dim bReturn, Results If hkRoot = HKEY_LOCAL_MACHINE Or hkRoot = HKEY_CURRENT_USER Or hkRoot = HKEY_CLASSES_ROOT Or hkRoot = HKEY_USERS Or hkRoot = HKEY_CURRENT_CONFIG Or hkRoot = HKEY_DYN_DATA Then 'Read Value Select Case nType Case REG_SZ ReadValue = objRegistry.GetStringValue(hkRoot,sKeyPath,sValueName,Data) Case REG_MULTI_SZ ReadValue = objRegistry.GetMultiStringValue(hkRoot,sKeyPath,sValueName,Data) Case REG_EXPAND_SZ ReadValue = objRegistry.GetExpandedStringValue(hkRoot,sKeyPath,sValueName,Data) Case REG_BINARY ReadValue = objRegistry.GetBinaryValue(hkRoot,sKeyPath,sValueName,Data) Case REG_DWORD ReadValue = objRegistry.GetDWORDValue(hkRoot,sKeyPath,sValueName,Data) End Select End If End Function