Write a value to the Registry
Syntax
objShell.RegWrite strRegName, anyValue, [strType]
Arguments:
objShell A WScript.Shell object
strRegName
To set a key instead of a value terminate strRegName
with a backslash character \
strRegName must start with one of
HKEY_CURRENT_USER or HKCU
HKEY_USERS
HKEY_LOCAL_MACHINE or HKLM
HKEY_CLASSES_ROOT or HKCR
HKEY_CURRENT_CONFIG
strType
The data type, one of:
REG_SZ, REG_EXPAND_SZ, (String values)
REG_DWORD (convert to Integer value)
REG_BINARY (Integer value)
When you specify a key-name (as opposed to a value-name), RegRead returns the default value.
Examples
Set the registry flag to display Hidden and System files in Windows Explorer:
Set WshShell = CreateObject("WScript.Shell")
myKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden"
WshShell.RegWrite myKey,1,"REG_DWORD"
Set the registry flag to hide Hidden and System files in Windows Explorer (the default)
Set WshShell = CreateObject("WScript.Shell")
myKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden"
WshShell.RegWrite myKey,0,"REG_DWORD"
Create a "default value" at HKCU\KeyName\ n.b. the trailing backslash is required:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\KeyName\","", "REG_SZ"
“Nothing is permanent” - Buddha
Related:
Registry, delete - WshShell.RegDelete
Registry, read - WshShell.RegRead
Q281309 - Unable to Use a "\" in a Key Name with RegWrite
Equivalent Windows CMD command: REG - Read, Set or Delete registry keys and values
Equivalent PowerShell cmdlet: Set-Item