2013-12-13 49 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