SoFunction
Updated on 2025-04-13

VBS scripts use WMI to operate the registry code


'Read MultiString value
const HKEY_LOCAL_MACHINE = &H80000002   
strComputer = "."  
Set StdOut =    
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_    
strComputer & "\root\default:StdRegProv")   
strKeyPath = "SYSTEM\CurrentControlSet\Services\Eventlog\System"  
strValueName = "Sources"  
 HKEY_LOCAL_MACHINE,strKeyPath,_   
strValueName,arrValues   
For Each strValue In arrValues   
      strValue   
Next  

  

'Read the extended string value
const HKEY_LOCAL_MACHINE = &H80000002   
strComputer = "."  
Set StdOut =    
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_    
strComputer & "\root\default:StdRegProv")   
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon"  
strValueName = "UIHost"  
 HKEY_LOCAL_MACHINE,strKeyPath,_   
strValueName,strValue   
  "The Windows logon UI host is: " & strValue   

  

'Read the string and DWORD value

const HKEY_CURRENT_USER = &H80000001   
const HKEY_LOCAL_MACHINE = &H80000002   
strComputer = "."  
Set StdOut =    
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_   
 strComputer & "\root\default:StdRegProv")   
strKeyPath = "Console"  
strValueName = "HistoryBufferSize"  
 HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue   
 "Current History Buffer Size: " & dwValue    
strKeyPath = "SOFTWARE\Microsoft\Windows Script Host\Settings"  
strValueName = "TrustPolicy"  
 HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue   
 "Current WSH Trust Policy Value: " & strValue   

'-------------------------------------------------------------------------------------------   

Const HKEY_CLASSES_ROOT = &H80000000   
Const HKEY_CURRENT_USER = &H80000001   
Const HKEY_LOCAL_MACHINE = &H80000002   
Const HKEY_USERS = &H80000003   
Const HKEY_CURRENT_CONFIG = &H80000005   

strComputer = "."  
Set StdOut =    
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")   

  

'Create a registry key
strKeyPath = "SOFTWARE\System Admin Scripting Guide"  
 HKEY_LOCAL_MACHINE,strKeyPath   

'Create multi-string value

strValueName = "Multi String Value Name"  
arrStringValues = Array("first string", "second string", "third string", "fourth string")   
 HKEY_LOCAL_MACHINE,strKeyPath,strValueName,arrStringValues   

'Create an extended string value
strValueName = "Expanded String Value Name"  
strValue = "%PATHEXT%"  
 HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue   

'Create a string
strValueName = "String Value Name"  
strValue = "string value"  
 HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue   

'Create DWORD value
strValueName = "DWORD Value Name"  
dwValue = 82   
 HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue   

'Create binary value
strValueName = "Binary Value Name"  
uBinary = Array(1,0,0,0)   
 HKEY_LOCAL_MACHINE,strPath,strValueName,uBinary   

  
'Delete the registry key
strKeyPath = "SOFTWARE\System Admin Scripting Guide"  
 HKEY_LOCAL_MACHINE, strKeyPath   

  
'Delete the registry value

strDWORDValueName = "DWORD Value Name"  
strExpandedStringValueName = "Expanded String Value Name"  
strMultiStringValueName = "Multi String Value Name"  
strStringValueName = "String Value Name"  
 HKEY_LOCAL_MACHINE,strKeyPath,strDWORDValueName   
 HKEY_LOCAL_MACHINE,strKeyPath,strExpandedStringValueName   
 HKEY_LOCAL_MACHINE,strKeyPath,strMultiStringValueName   
 HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName   

  
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'Read MultiString value
strKeyPath = "SYSTEM\CurrentControlSet\Services\Eventlog\System"  
strValueName = "Sources"  
 HKEY_LOCAL_MACHINE,strKeyPath,strValueName,arrValues   
For Each strValue In arrValues   
      strValue   
Next  

'Read the extended string value
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon"  
strValueName = "UIHost"  
 HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue   
  "The Windows logon UI host is: " & strValue   

'Read the string value
strKeyPath = "Console"  
strValueName = "HistoryBufferSize"  
 HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue   
 "Current History Buffer Size: " & dwValue    

'Read the DWORD value
strKeyPath = "SOFTWARE\Microsoft\Windows Script Host\Settings"  
strValueName = "TrustPolicy"  
 HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue   
 "Current WSH Trust Policy Value: " & strValue   

'Read the binary registry value
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"  
strValueName = "LicenseInfo"  
 HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue   
For i = lBound(strValue) to uBound(strValue)   
      strValue(i)   
Next