Re: Help with reading remote registries

From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 01/18/05


Date: Tue, 18 Jan 2005 19:02:20 +0100

Derek wrote:

> Hello,
> I am having trouble with the following script. Could someone please help me
> figure out why I am not able to retrieve the registry key properly from a
> list of computers I am reading from a text file? The script runs fine when
> searching the local computer but will not retrieve the registry key
> remotely? Any help is appreciated, thanks!
>
> Derek
>
> Option Explicit
> On Error Resume Next

Never use a "global" On Error Resume Next during testing and
when having problems!

[snip]
>
> For Each strComputer In arrComputers
> Do While Not objTextFile.AtEndOfStream

You should remove the "Do While" loop as it is not valid any more and
will make the script go into a eternal loop (remove the "On Error
Resume Next" and you will get an error on it).

> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set objRegistry = GetObject("winmgmts:\\" & _
> strComputer & "\root\default:StdRegProv")
>
> strKeyPath = "SOFTWARE\Veritas\NetBackup\CurrentVersion\"
> strValueName = "version"
> objRegistry.GetStringValue
> HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
>
> If IsNull(strValue) Then
> objfile.Write strComputer & "The registry key does not exist."
> Else
> objfile.Write strComputer,strValue

Again, your "On Error Resume Next" suppresses an error here. The line
above will always fail. Change it to:

objfile.Write strComputer & strValue

> End If
>
>
> objfile.Write VbCrLf & String(80, "-")
> Loop

Remove "Loop".

> Next

-- 
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx


Relevant Pages

  • Re: Memory output format
    ... And you need to set strDescription to a blank ... All values must be retrieved in the "Do Until" loop, ... I am using your script in the middle of a script pulling wmi info from ... The error is raised when the program attempts to retrieve the value of the ...
    (microsoft.public.scripting.wsh)
  • Re: Memory output format
    ... And you need to set strDescription to a blank ... All values must be retrieved in the "Do Until" loop, ... I am using your script in the middle of a script pulling wmi info from ... The error is raised when the program attempts to retrieve the value of the ...
    (microsoft.public.scripting.wsh)
  • Re: Force password Expiration to 5 days
    ... Then when the day arrives you can run a script or program that either: ... Expires everyones password, ... I have a VBScript program that converts ... A filter to retrieve all users that have not change their password since ...
    (microsoft.public.windows.server.scripting)
  • Re: Memory output format
    ... The error is raised when the program attempts to retrieve the value of the ... sAMAccountName attribute, but that attribute is not listed in the query as ... I'm having another issue with my script. ... FormatNumber strTotalPhysicalMemory ...
    (microsoft.public.scripting.wsh)
  • Re: Getting computer in AD domain
    ... which cannot be used in a script. ... in VBScript to retrieve information from AD. See this link: ... You can retrieve any attribute values desired. ... Not sure how to use this, as I don't use VBScript ...
    (microsoft.public.scripting.vbscript)