Home > Programmering, Windows > Read and write to registry in Windows 7 with VBS

Read and write to registry in Windows 7 with VBS

Here’s an example of how you can use VBS script to access the registry in Windows. Tested in Win7.

'_____________________________________________________________________________
' REMOVE POP-UP'S
'
' v1.00 2011-05-16 Lenovo Fingerprint software /Tobias Holm / http://xpro.se
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
lRet = RegWriteW7("HKEY_CURRENT_USER\Software\Protector Suite\Control Center\1.0\ShowOnStartup", "0", "REG_DWORD")
msgbox "WRITE:" & lRet & " ERR:" & Err
lRet = RegReadW7("HKEY_CURRENT_USER\Software\Protector Suite\Control Center\1.0\ShowOnStartup")
msgbox "READ:" & lRet & " ERR:" & Err
lRet = RegDelW7("HKEY_CURRENT_USER\Software\Protector Suite\Control Center\1.0\ShowOnStartup")
msgbox "DEL:" & lRet & " ERR:" & Err

'______________________________________________________________________________________
' WRITE TO REGISTRY / Tobias Holm 2011-05-16 / http://xpro.se
' Original idea Guy Thomas http://computerperformance.co.uk (Version 1.2 - March 2007)
' Creates the registry keys if they doesn't exists.
' Ex: lRet = RegWriteW7("HKEY_CURRENT_USER\Software\Intel\Count", "35", "REG_DWORD")
' Returns the exit code from Shell.RegWrite
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Function RegWriteW7(x_sPath, x_sValue, x_sType)
On Error Resume Next
Dim x_objShell
Set x_objShell = CreateObject("WScript.Shell")
Err.Clear
RegWriteW7 = x_objShell.RegWrite(x_sPath, x_sValue, x_sType)
Set x_objShell = Nothing
End Function

'______________________________________________________________________________________
' READ FROM REGISTRY / Tobias Holm 2011-05-16 / http://xpro.se
' Original idea Guy Thomas http://computerperformance.co.uk (Version 1.2 - March 2007)
' Ex: lRet = RegReadW7("HKEY_CURRENT_USER\Software\Intel\Count")
' Returns the value from Shell.RegRead
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Function RegReadW7(x_sPath)
On Error Resume Next
Dim x_objShell
Set x_objShell = CreateObject("WScript.Shell")
Err.Clear
RegReadW7 = x_objShell.RegRead(x_sPath)
Set x_objShell = Nothing
End Function

'______________________________________________________________________________________
' DELETE FROM REGISTRY / Tobias Holm 2011-05-16 / http://xpro.se
' Original idea Guy Thomas http://computerperformance.co.uk (Version 1.2 - March 2007)
' Deletes a registry value. Doesn't delete the registry keys though.
' Ex: lRet = RegDelW7("HKEY_CURRENT_USER\Software\Intel\Count")
' Returns the exit code from Shell.RegDelete
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Function RegDelW7(x_sPath)
On Error Resume Next
Dim x_objShell
Set x_objShell = CreateObject("WScript.Shell")
Err.Clear
RegDelW7 = x_objShell.RegDelete(x_sPath)
Set x_objShell = Nothing
End Function
Categories: Programmering, Windows Tags:
  1. No comments yet.
  1. No trackbacks yet.