Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Read remote registry in script

Reply
 
Old 10-15-2009   #1 (permalink)
Peter


 
 

Read remote registry in script

I have a VBS script that needs to read a registry value from remote computers
on a LAN, my efforts so far have led me to what I show below. It generates an
error trying to use the GetString method on the ObjWMIService object. A
little research shows me that this was not a valid method for an object
returned from the ConnectServer method.
I use the SWbemLocator.ConnectServer method since the logged in user of the
remote computers do not have access to registry editing.
I am stumped as to where to go next, I am sure this is a simple task but I
am not smart enough to get past this, any thoughts appreciated.

-------------------- Begin Script---------------
Option Explicit

Const HKEY_CURRENT_USER = &H80000001
Dim StrComputer, StrNameSpace, StrUserName, StrPassword
Dim StrPath, StrKey, StrValue
Dim ObjWMIService, ObjWbemLocator


StrComputer = "Comp01"
StrNameSpace = "\root\default:StdRegProv"
StrUserName = "adminuser"
StrPassword = "correctpassword"

Set ObjWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set ObjWMIService = objWbemLocator.ConnectServer(StrComputer, _
StrNameSpace, StrUserName, StrPassword)

StrKey = "SOFTWARE\Microsoft\Office\11.0\Outlook\Security"
StrValue = "OutlookSecureTempFolder"
ObjWMIService.GetStringValue HKEY_CURRENT_USER, StrKey, StrValue, StrPath
MsgBox StrPath
-------------------------- End Script --------------------
--
Regards - Peter


My System SpecsSystem Spec
Old 10-15-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Read remote registry in script

Peter wrote:
Quote:

>I have a VBS script that needs to read a registry value from remote
>computers
> on a LAN, my efforts so far have led me to what I show below. It generates
> an
> error trying to use the GetString method on the ObjWMIService object. A
> little research shows me that this was not a valid method for an object
> returned from the ConnectServer method.
> I use the SWbemLocator.ConnectServer method since the logged in user of
> the
> remote computers do not have access to registry editing.
> I am stumped as to where to go next, I am sure this is a simple task but I
> am not smart enough to get past this, any thoughts appreciated.
>
> -------------------- Begin Script---------------
> Option Explicit
>
> Const HKEY_CURRENT_USER = &H80000001
> Dim StrComputer, StrNameSpace, StrUserName, StrPassword
> Dim StrPath, StrKey, StrValue
> Dim ObjWMIService, ObjWbemLocator
>
>
> StrComputer = "Comp01"
> StrNameSpace = "\root\default:StdRegProv"
> StrUserName = "adminuser"
> StrPassword = "correctpassword"
>
> Set ObjWbemLocator = CreateObject("WbemScripting.SWbemLocator")
> Set ObjWMIService = objWbemLocator.ConnectServer(StrComputer, _
> StrNameSpace, StrUserName, StrPassword)
>
> StrKey = "SOFTWARE\Microsoft\Office\11.0\Outlook\Security"
> StrValue = "OutlookSecureTempFolder"
> ObjWMIService.GetStringValue HKEY_CURRENT_USER, StrKey, StrValue, StrPath
> MsgBox StrPath
> -------------------------- End Script --------------------
> --
> Regards - Peter
>
I can't verify at the moment, but I believe that once you are authenticated
to the remote computer, you can bind to other objects on the computer with
the same permissions. For example:
=======
Dim objReg

Set ObjWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set ObjWMIService = objWbemLocator.ConnectServer(StrComputer, _
StrNameSpace, StrUserName, StrPassword)
Set objReg = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
& strComputer & strNameSpace)

StrKey = "SOFTWARE\Microsoft\Office\11.0\Outlook\Security"
StrValue = "OutlookSecureTempFolder"
objReg.GetStringValue HKEY_CURRENT_USER, StrKey, StrValue, StrPath
========
However, if the computer is remote, I don't think you can access the
HKEY_CURRENT_USER hive.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 10-21-2009   #3 (permalink)
Peter


 
 

Re: Read remote registry in script

Richard, thanks for the reply.

Your idea did indeed prevent the error I was having, but the result returned
was null which suggests that your closing thoughts about loading the HKCU
hive from remote machines using VBScript is likely right. Now you mentioned
it I seem to recall reading something about that in an MS scripting article
which I cannot seem to find again.

Thanks again for your help.
--
Regards - Peter


"Richard Mueller [MVP]" wrote:
Quote:

> Peter wrote:
>
Quote:

> >I have a VBS script that needs to read a registry value from remote
> >computers
> > on a LAN, my efforts so far have led me to what I show below. It generates
> > an
> > error trying to use the GetString method on the ObjWMIService object. A
> > little research shows me that this was not a valid method for an object
> > returned from the ConnectServer method.
> > I use the SWbemLocator.ConnectServer method since the logged in user of
> > the
> > remote computers do not have access to registry editing.
> > I am stumped as to where to go next, I am sure this is a simple task but I
> > am not smart enough to get past this, any thoughts appreciated.
> >
> > -------------------- Begin Script---------------
> > Option Explicit
> >
> > Const HKEY_CURRENT_USER = &H80000001
> > Dim StrComputer, StrNameSpace, StrUserName, StrPassword
> > Dim StrPath, StrKey, StrValue
> > Dim ObjWMIService, ObjWbemLocator
> >
> >
> > StrComputer = "Comp01"
> > StrNameSpace = "\root\default:StdRegProv"
> > StrUserName = "adminuser"
> > StrPassword = "correctpassword"
> >
> > Set ObjWbemLocator = CreateObject("WbemScripting.SWbemLocator")
> > Set ObjWMIService = objWbemLocator.ConnectServer(StrComputer, _
> > StrNameSpace, StrUserName, StrPassword)
> >
> > StrKey = "SOFTWARE\Microsoft\Office\11.0\Outlook\Security"
> > StrValue = "OutlookSecureTempFolder"
> > ObjWMIService.GetStringValue HKEY_CURRENT_USER, StrKey, StrValue, StrPath
> > MsgBox StrPath
> > -------------------------- End Script --------------------
> > --
> > Regards - Peter
> >
>
> I can't verify at the moment, but I believe that once you are authenticated
> to the remote computer, you can bind to other objects on the computer with
> the same permissions. For example:
> =======
> Dim objReg
>
> Set ObjWbemLocator = CreateObject("WbemScripting.SWbemLocator")
> Set ObjWMIService = objWbemLocator.ConnectServer(StrComputer, _
> StrNameSpace, StrUserName, StrPassword)
> Set objReg = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
> & strComputer & strNameSpace)
>
> StrKey = "SOFTWARE\Microsoft\Office\11.0\Outlook\Security"
> StrValue = "OutlookSecureTempFolder"
> objReg.GetStringValue HKEY_CURRENT_USER, StrKey, StrValue, StrPath
> ========
> However, if the computer is remote, I don't think you can access the
> HKEY_CURRENT_USER hive.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
> .
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
read registry key(s) on some remote machines PowerShell
Script: read a registry key VB Script
Need to read 64-bit registry from 32-bit RegRead VB Script
Re: Printer cannot read registry key? Vista print fax & scan
Read from Registry on Vista Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46