How to Add a Registry Key Using Vbscript?
I Want to Add a Registry Key (Dword=1) in Hkey_Local_Machine \System\Currentcontrolset\Control\Storagedevicepolicies Using Vbscript. How Can I Do That? 2...
I want to add a registry key (DWORD=1) in HKEY_LOCAL_MACHINE \SYSTEM\CurrentControlSet\Control\StorageDevicePolicies using VBScript. How can I do that?
2 Answers
An example of registry entry creation would be:
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Script Center"
strValueName = "My DWORD Value"
dwValue = 13
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue
where the targets can be changed accordingly to your needs.
Some examples:
Example 1: 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 WshShell = Nothing
Example 2: 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"
Set WshShell = Nothing
Example 3: Create a "default value" at KCU\KeyName\
Note: The trailing backslash is required:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\KeyName\","", "REG_SZ"
Set WshShell = Nothing
Credit to