Read/Write Registry Key

Working with the Windows Registry is not so complex as we can think. Using WScript.Shell object is possible use regread and regwrite methods to read and write registry key.

 

With this example we'll update first the value of the REG_SZ key "HKEY_CURRENT_USER\MyUtilities\UPH" and then we'll read it

 

'***********************************************

'**************** MAIN **************************

'***********************************************

Const MyRegKey = "HKEY_CURRENT_USER\MyUtilities\UPH"

 

Dim myshell, strValue

strValue = ""

 

set myshell = CreateObject("Wscript.Shell")

 

'write of a value into the registry key

myshell.regwrite MyRegKey, "Value", "REG_SZ"

 

'To create a new registry key "folder" use the same instruction

'without last parameter and empty value:

'myshell.regwrite "HKEY_CURRENT_USER\MyUtilities\, ""

 

'read the value

strValue = myshell.regread(MyRegKey)

 

'now show the value through a timed popup (5 sec.)

myshell.Popup "The value of the Registry Key " & MyRegKey & " is: " & strValue, 5, "Reading Key Value", 64

 

'Destruction of the Wscript.Shell object

set myshell = nothing

 

'******************************************************

'************** FINE MAIN *******************************

'******************************************************

 

______________________________________________________________________

 

 

Pag: <<    <    >    >>