2013-12-13 50 views
0

我使用以下代码创建Windows注册表项。无法在Windows注册表中写入适当的位置

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 

我在管理域帐户下执行该脚本,并且该帐户本地具有管理权限。

我在这里错过了什么?

P.S.我发现这Why is registry written in different location than expected?,但它不清楚我如何更改我的代码...

+0

见http://www.server-world.info/en/note?os=Other&p=vbs也http://stackoverflow.com/questions/17466681/how-to-run-vbs-作为管理员从 - VBS – klugerama

回答

0

我发现这是Windows的正确行为。 http://msdn.microsoft.com/en-us/library/windows/desktop/aa965884(v=vs.85).aspx

我用另一个代码检查了它。所以我可以读取适当的价值。

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