Thursday, September 3, 2015

How to work with Windows registry

To work with Windows registry using WScript.Shell object.


If you want to read a specific Key from registry
Set wscriptObj=createobject("WScript.Shell")
objProperties=wscriptObj.RegRead("HKLM\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Browser\CommonUse\")
msgbox objProperties
The above will give you the "Default" property value

If you want to read a specific property name in the registry:
objProperties=wscriptObj.RegRead("HKLM\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Browser\CommonUse\Sync")

If you want to update a specific property value in the registry:
wscriptObj.RegWrite "HKLM\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Browser\CommonUse\Sync",0,"REG_DWORD"

If you want to delete a specific property from the registry:
wscriptObj.RegDelete "HKLM\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Browser\CommonUse\Sync"


You can also use DotNetFactory to retrieve any retrieve any value
registryPath1="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE"
'Here i am creating an instance of DotNet Factory computer object
Set objDFComputer=DotNetFactory("Microsoft.VisualBasic.Devices.Computer","Microsoft.VisualBasic")
'Here i am creating an instance of Registry Object
Set objRegistry=objDFComputer.Registry
'The below will retrieve the "Default" Property
print objRegistry.GetValue(registryPath1,"","")

'The below retrieves the property of the regsitry
print objRegistry.GetValue(registryPath1,"Path","")
Set objRegistry=nothing
Set objDFComputer=nothing

No comments:

Post a Comment