Vbscript 使用VBS更新注册表
我正在尝试使用VBScript更新电脑上的合法标题。到目前为止,我已经能够读取值,但我似乎无法让它写入任何值。我在运行脚本时没有收到错误,它只是没有改变任何东西。这是我第一次这样做,我的经验有限;如有任何见解,将不胜感激:Vbscript 使用VBS更新注册表,vbscript,registrykey,Vbscript,Registrykey,我正在尝试使用VBScript更新电脑上的合法标题。到目前为止,我已经能够读取值,但我似乎无法让它写入任何值。我在运行脚本时没有收到错误,它只是没有改变任何东西。这是我第一次这样做,我的经验有限;如有任何见解,将不胜感激: Dim objShell Dim strMessage, strWelcome, strWinLogon ' Set the string values strWelcome = "legalnoticecaption" strMessage = "did this wor
Dim objShell
Dim strMessage, strWelcome, strWinLogon
' Set the string values
strWelcome = "legalnoticecaption"
strMessage = "did this work"
strWinLogon = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\"
' Create the Shell object
Set wshShell = CreateObject("WScript.Shell")
'Display string Values
Wscript.Echo "key to update: " & strWelcome
Wscript.Echo "key value to enter: " & strMessage
Wscript.Echo "Existing key value: " & wshShell.RegRead(strWinLogon & strWelcome)
' the crucial command in this script - rewrite the registry
wshShell.RegWrite strWinLogon & strWelcome, strMessage, "REG_SZ"
' Did it work?
Wscript.Echo "new key value: " & wshShell.RegRead(strWinLogon & strWelcome)
set wshShell = Nothing
注意:这些是目前的测试值。对我来说,您的代码运行得非常完美。 对于其他需要详细信息的用户,我推荐这个网站:和
这两个链接都详细说明了您创建的过程。您的脚本似乎没有bug。但是,由cscript 28416995.vbs启动时返回下一个错误(其中22=
WshShell.RegWrite
line):
28416995.vbs(22,1)WshShell.RegWrite:注册表项“HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policys\System\LegalNoticeOption”中的根目录无效
它不是无效的根目录,它类似于拒绝访问,而是因为写入HKLM
需要提升权限(或以管理员身份运行)
注:
- 您应该将
值与LegalNoticeText
one一起更改LegalNoticeCaption
- 在
注册表项下,这两个值也存在。对于这种情况(如果计算机未连接到域或禁用了组策略),应在下一个脚本中使用李>HKLM\SOFTWARE\Microsoft\windowsnt\CurrentVersion\Winlogon\
option explicit
On Error Goto 0
Dim wshShell
Dim strResult, strMessage, strWelcome, strWinLogon, strWinLog_2, strWinLTxt
strResult=Wscript.ScriptName
' Set the string values
strWinLTxt = "legalnoticetext"
strWelcome = "legalnoticecaption"
strMessage = "did this work"
strWinLogon = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\"
strWinLog_2 = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\"
' Create the Shell object
Set wshShell = CreateObject("WScript.Shell")
'Display string Values
' continue execution if requested registry values not present
On Error Resume Next
strResult = strResult & vbNewLine & "Existing Caption Policies: " _
& wshShell.RegRead(strWinLog_2 & strWelcome)
strResult = strResult & vbNewLine & "Existing Text Policies: " _
& wshShell.RegRead(strWinLog_2 & strWinLTxt)
On Error Goto 0
strResult = strResult & vbNewLine & "Existing Caption Winlogon: " _
& wshShell.RegRead(strWinLogon & strWelcome)
strResult = strResult & vbNewLine & "Existing Text Winlogon: " _
& wshShell.RegRead(strWinLogon & strWinLTxt)
strResult = strResult & vbNewLine
strResult = strResult & vbNewLine & "key to update: " & strWelcome
strResult = strResult & vbNewLine & "key value to enter: " & strMessage
' the crucial command in this script - rewrite the registry
wshShell.RegWrite strWinLogon & strWelcome, strMessage, "REG_SZ"
wshShell.RegWrite strWinLogon & strWinLTxt, UCase( strMessage), "REG_SZ"
' Did it work?
strResult = strResult & vbNewLine
strResult = strResult & vbNewLine _
& "new key Capt. value: " & wshShell.RegRead(strWinLogon & strWelcome)
strResult = strResult & vbNewLine _
& "new key Text value: " & wshShell.RegRead(strWinLogon & strWinLTxt)
Wscript.Echo strResult
set wshShell = Nothing