如何使用 VBScript 添加注册表项?

如何使用 VBScript 添加注册表项?

我想HKEY_LOCAL_MACHINE \SYSTEM\CurrentControlSet\Control\StorageDevicePolicies使用 VBScript 添加注册表项 (DWORD=1)。我该怎么做?

答案1

注册表条目创建的一个例子是:

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

其中目标可以根据您的需要进行相应更改。

来源

答案2

一些例子:

示例 1:设置注册表标志以在 Windows 资源管理器中显示隐藏文件和系统文件:

Set WshShell = CreateObject("WScript.Shell")
myKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden"
WshShell.RegWrite myKey,1,"REG_DWORD"
Set WshShell = Nothing

示例 2:设置注册表标志以隐藏 Windows 资源管理器中的隐藏文件和系统文件(默认):

Set WshShell = CreateObject("WScript.Shell")
myKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden"
WshShell.RegWrite myKey,0,"REG_DWORD"
Set WshShell = Nothing

示例 3:在创建“默认值”KCU\KeyName\
注意:末尾的反斜杠是必需的

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\KeyName\","", "REG_SZ"
Set WshShell = Nothing

归功于http://ss64.com

相关内容