Forum Discussion
JDR2500
8 days agoFrequent Contributor
Using VBScript we write string, DWORD and binary values anywhere in HKEY_CURRENT_USER using the following routine.
'Example usage:
' SetRegistryValue ("Software\SmartBear\TestComplete\15.0", "EdgeReloadRequired", 1, "DWORD")
'___________________________________________________________________________________________________________________________________________________
Sub SetRegistryValue(s_KeyPath, s_ValueName, s_Value, s_Type)
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
If (s_Type = "DWORD") Then
objRegistry.SetDWORDValue HKEY_CURRENT_USER, s_KeyPath, s_ValueName, s_Value
ElseIf (s_Type = "Binary") Then 'If the registry is binary
uBinary = Split(s_Value) 'This will split up a string into an array using the space as a splitter.
'This will convert each segment of the array into hex rather than string
For i = 0 To UBound(uBinary) : uBinary(i) = CByte("&H" & uBinary(i)) : Next
'This will write the array of hex values to a binary value in the registry
Call objRegistry.SetBinaryValue(HKEY_CURRENT_USER, s_KeyPath, s_ValueName, uBinary)
ElseIf (s_Type = "String") Then
objRegistry.SetStringValue HKEY_CURRENT_USER, s_KeyPath, s_ValueName, s_Value
End If
Set objRegistry = Nothing
End Sub
To read DWORD or String values from HKEY_CURRENT_USER we use this function:
'Example:
' AtsGetRegistryValue ("Software\SmartBear\TestComplete\15.0", "EdgeReloadRequired", "DWORD")
'___________________________________________________________________________________________________________________________________________________
Function AtsGetRegistryValue(s_KeyPath, s_ValueName, s_Type)
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
If (s_Type = "DWORD") Then
objRegistry.GetDWORDValue HKEY_CURRENT_USER, s_KeyPath, s_ValueName, AtsGetRegistryValue 'Assign the DWORD to the "Function". This
will make the DWORD the returned value for the function.
ElseIf (s_Type = "String") Then
objRegistry.GetStringValue HKEY_CURRENT_USER, s_KeyPath, s_ValueName, AtsGetRegistryValue
End If
Set objRegistry = Nothing
End Function
Related Content
- 2 years ago
- 5 years ago
Recent Discussions
- 21 hours ago