WSH » wshshell » RegWrite

Syntax:
WshShell.RegWrite (strName, varValue [,strType])
varValue
If strType is "REG_SZ" or "REG_EXPAND_SZ", then varValue is automatically converted to a string. If strType is "REG_DWORD", varValue is converted to an integer. If strType is "REG_BINARY", then varValue must be an integer.
strType
Supported values for strType are "REG_SZ", "REG_EXPAND_SZ", "REG_DWORD", and "REG_BINARY". If any other data type is passed as strType, RegWrite returns E_INVALIDARG.

The RegWrite method writes a new entry into the registry.

The RegWrite method writes either a key or a value to the registry based on strName. If strName ends with a backslash (\), then RegWrite writes varValue to the registry as a key. Otherwise it writes varValue to the registry as a value. The strName parameter must begins with one of the following root key names:

  • HKEY_CURRENT_USER or HKCU
  • HKEY_LOCAL_MACHINE or HKLM
  • HKEY_CLASSES_ROOT or HKCR
  • HKEY_USERS
  • HKEY_CURRENT_CONFIG

Examples

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\MyNewKey\", 1 ,"REG_DWORD"
WshShell.RegWrite "HKCU\MyNewKey\MyValue", "Hello world!"

WScript.Echo WshShell.RegRead("HKCU\MyNewKey\MyValue")
WScript.Echo WshShell.RegRead("HKCU\MyNewKey\")

WshShell.RegDelete "HKCU\MyNewKey\MyValue"
WshShell.RegDelete "HKCU\MyNewKey\"
Output:
Hello World!
1
Explanation:

This VBScript code writes a key/value pair into the registry, reads and displays their content, and finally removes them from the registry.

Language(s): VBScript