How to add a registry key using VBScript?

-1

I want to add a registry key (DWORD=1) in HKEY_LOCAL_MACHINE \SYSTEM\CurrentControlSet\Control\StorageDevicePolicies using VBScript. How can I do that?

powermun50

Posted 2013-04-06T14:42:53.920

Reputation: 51

Answers

4

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.

Source

Lorenzo Von Matterhorn

Posted 2013-04-06T14:42:53.920

Reputation: 2 137

I am sorry. But i didn't understand. can you give me exact script for HKEY_LOCAL_MACHINE \SYSTEM\CurrentControlSet \Control\StorageDevicePolicies? – powermun50 – 2013-04-06T15:25:16.060

4@powermun50 if you can't rewrite this script to suit your needs you probably shouldn't be editing the registry. – MDMoore313 – 2013-04-06T15:40:36.987

1@MDMoore313: Very well said! – Karan – 2013-04-06T16:15:16.687

0

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 http://ss64.com

Stanly K Joseph

Posted 2013-04-06T14:42:53.920

Reputation: 1