Vbscript 无法写入Windows注册表中的正确位置
我使用以下代码创建Windows注册表项Vbscript 无法写入Windows注册表中的正确位置,vbscript,registry,Vbscript,Registry,我使用以下代码创建Windows注册表项 Dim WshShell Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.RegWrite "HKLM\Software\NewsReader\ConnectionString1", "Server=myServerName3\myInstanceName1;Database=myDataBase1;User Id=myUsername1;Password=myPasswor
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKLM\Software\NewsReader\ConnectionString1", "Server=myServerName3\myInstanceName1;Database=myDataBase1;User Id=myUsername1;Password=myPassword1;", "REG_SZ"
Set WshShell = Nothing
不知怎的,它写错地方了
HKEY_USERS\S-1-5-21-3289046681-1693842953-402210132-1123\Software\Classes\VirtualStore\MACHINE\SOFTWARE\NewsReader
我在admin域帐户下执行该脚本,并且该帐户在本地具有管理员权限
我在这里错过了什么
另外,我发现了这一点,但不清楚我必须如何更改代码…即使该帐户具有管理员权限,但由于UAC,脚本仍必须显式提升权限。有关如何执行此操作的一些想法,请参阅。我发现这是Windows的正确行为。 我用另一个代码检查了它。这样我就可以读取正确的值
Dim WSHShell, value
On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
value = WSHShell.RegRead("HKLM\Software\NewsReader\ConnectionString1")
If err.number <> 0 Then
MsgBox("Error")
Else
MsgBox(value)
End If
Set WSHShell = nothing
Dim WSHShell,值
出错时继续下一步
设置WSHShell=CreateObject(“WScript.Shell”)
value=WSHShell.regrad(“HKLM\Software\NewsReader\ConnectionString1”)
如果错误号为0,则
MsgBox(“错误”)
其他的
MsgBox(值)
如果结束
设置WSHShell=nothing
另请参见和