0

I use following code to create Windows registry entry.

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

Somehow it is writing in a wrong place.

HKEY_USERS\S-1-5-21-3289046681-1693842953-402210132-1123\Software\Classes\VirtualStore\MACHINE\SOFTWARE\NewsReader

I execute that script under admin domain account and also that account has Admin privileges locally.

What do I am missing here?

P.S. I found this Why is registry written in different location than expected? but it does not clear how I have to change my code...

Community
  • 1
  • 1
NoWar
  • 36,338
  • 80
  • 323
  • 498
  • See http://www.server-world.info/en/note?os=Other&p=vbs and also http://stackoverflow.com/questions/17466681/how-to-run-vbs-as-administrator-from-vbs – klugerama Dec 13 '13 at 17:30

2 Answers2

1

Even though the account has admin privileges, the script must still explicitly elevate privileges due to UAC. See http://www.server-world.info/en/note?os=Other&p=vbs for some ideas on how to do this.

klugerama
  • 3,312
  • 19
  • 25
0

I found that is a correct behavior of the Windows. http://msdn.microsoft.com/en-us/library/windows/desktop/aa965884(v=vs.85).aspx

And I checked it with another code. So I could read proper value.

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
NoWar
  • 36,338
  • 80
  • 323
  • 498