Solved

Checking a registry value for multiple machines (against a text file of computer names)

Posted on 2009-07-05
13
559 Views
Last Modified: 2012-06-21
Hi guys, hope you can help.

Id like to check the existence of a value in the registry for multiple machines.

I have a text file which lists a list of computer names. c:\computers.txt

What id like is:

For each computer lin c:\computers.txt,
1) Check if you can connect to each.
2) If you can, check if you can read the following registry key's value:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\9040210900063D11C8EF10054038389C\Patches\AD59682ADCB5BCA4986BD99DC095ABBE /v DisplayName

3) If the value is:
Security Update for Office 2003 (KB954478): GDIPLUS

then write  the computer name and "Success" to Output.txt
If the key doesnt exist, or you cannot connect, then
write  the computer name and "Failure" to Output.txt

===================================== Output.txt
<computername>    Success
<computername>    Failure
etc
etc

Any help greatly appreciated.


reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\9040210900063D11C8EF10054038389C\Patches\AD59682ADCB5BCA4986BD99DC095ABBE /v DisplayName
 

The output is as follows:
 

! REG.EXE VERSION 3.0
 

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\

S-1-5-18\Products\9040210900063D11C8EF10054038389C\Patches\AD59682ADCB5BCA4986BD

99DC095ABBE

    DisplayName REG_SZ  Security Update for Office 2003 (KB954478): GDIPLUS

Open in new window

0
Comment
Question by:Simon336697
  • 7
  • 6
13 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 24783140
Hi Simon,

Try this out. I hope I've got it right....I haven't tested it yet....

Regards,

Rob.
Set objShell = CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")

Const intForReading = 1

strComputersFile = "Computers.txt"

strLogFile = "RegistryCheckLog.txt"

Set objComputersFile = objFSO.OpenTextFile(strComputersFile, intForReading, False)

Set objLogFile = objFSO.CreateTextFile(strLogFile, True)

While Not objComputersFile.AtEndOfStream

	strComputer = objComputersFile.ReadLine

	If Ping(strComputer) = True Then

		On Error Resume Next

		strValue = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\9040210900063D11C8EF10054038389C\Patches\AD59682ADCB5BCA4986BD99DC095ABBE\DisplayName")

		If Err.Number = 0 Then

			On Error GoTo 0

			If strValue = "Security Update for Office 2003 (KB954478): GDIPLUS" Then

				objLog.WriteLine strComputer & ": Correct value"

			Else

				objLog.WriteLine strComputer & ": Incorrect value"

			End If

		Else

			Err.Clear

			On Error GoTo 0

			objLog.WriteLine strComputer & ": RegRead Error"

		End If

	Else

		objLog.WriteLine strComputer & ": Offline"

	End If

Wend

objComputersFile.Close

objLog.Close

MsgBox "Finished. Please see " & strLogFile

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24783148
Ooops, forgot to add the Ping function....
Set objShell = CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")

Const intForReading = 1

strComputersFile = "Computers.txt"

strLogFile = "RegistryCheckLog.txt"

Set objComputersFile = objFSO.OpenTextFile(strComputersFile, intForReading, False)

Set objLogFile = objFSO.CreateTextFile(strLogFile, True)

While Not objComputersFile.AtEndOfStream

	strComputer = objComputersFile.ReadLine

	If Ping(strComputer) = True Then

		On Error Resume Next

		strValue = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\9040210900063D11C8EF10054038389C\Patches\AD59682ADCB5BCA4986BD99DC095ABBE\DisplayName")

		If Err.Number = 0 Then

			On Error GoTo 0

			If strValue = "Security Update for Office 2003 (KB954478): GDIPLUS" Then

				objLog.WriteLine strComputer & ": Correct value"

			Else

				objLog.WriteLine strComputer & ": Incorrect value"

			End If

		Else

			Err.Clear

			On Error GoTo 0

			objLog.WriteLine strComputer & ": RegRead Error"

		End If

	Else

		objLog.WriteLine strComputer & ": Offline"

	End If

Wend

objComputersFile.Close

objLog.Close

MsgBox "Finished. Please see " & strLogFile
 

Function Ping(strComputer)

    Dim objShell, boolCode

    Set objShell = CreateObject("WScript.Shell")

    boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)

    If boolCode = 0 Then

        Ping = True

    Else

        Ping = False

    End If

End Function

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 24783838
As always Rob youre just over the top in a good way mate :>)
Will test and let you know :>)
0
 
LVL 1

Author Comment

by:Simon336697
ID: 24790939
Hi Rob, mate that works really great.
Can i ask you just one more thing?

If i wanted to turn this into a hta, and in that hta, enter the following 3 things instead of hardcoding them in the vbs file:


================================================ script.hta

Please browse for a text file <Browse>

Please enter a registry key to search for _____________________________
(This would replace the hardcoding of strValue in the vbs file as seen below)

strValue =
objShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\9040210900063D11C8EF10054038389C\Patches\AD59682ADCB5BCA4986BD99DC095ABBE\DisplayName")

Please enter the value you are looking for, for the above key you entered: _________________
This would replace the:

If strValue = "Security Update for Office 2003 (KB954478): GDIPLUS"
in the vbs file.

<OK> button to run the script.

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24791349
OK, see how this goes.

Regards,

Rob.
<head>

<title>Remote Registry Check Application</title>

<HTA:APPLICATION 

     APPLICATIONNAME="Remote Registry Check Application"

     BORDER="thin"

     SCROLL="no"

     SINGLEINSTANCE="yes"

     WINDOWSTATE="normal"

>

</head>

 

<script language="VBScript">
 

Sub Window_OnLoad

	intWidth = 800

	intHeight = 600

	Me.ResizeTo intWidth, intHeight

	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))

End Sub
 

Sub Run_Script

	If txt_textfile.Value = "" Then

		MsgBox "Please select a text file."

		txt_textfile.Focus

	ElseIf txt_registrypath.Value = "" Then

		MsgBox "Please enter a registry path."

		txt_registrypath.Focus

	Else

		Set objShell = CreateObject("WScript.Shell")

		Set objFSO = CreateObject("Scripting.FileSystemObject")

		Const intForReading = 1

	    If Mid(document.location, 6, 3) = "///" Then

	    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)

	    Else

	    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)

	    End If

		strComputersFile = txt_textfile.Value

		strLogFile = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "RegistryCheckLog.txt"

		Set objComputersFile = objFSO.OpenTextFile(strComputersFile, intForReading, False)

		Set objLog = objFSO.CreateTextFile(strLogFile, True)

		While Not objComputersFile.AtEndOfStream

			strComputer = objComputersFile.ReadLine

			If Ping(strComputer) = True Then

				On Error Resume Next

				strValue = objShell.RegRead(txt_registrypath.Value)

				If Err.Number = 0 Then

					On Error GoTo 0

					If LCase(strValue) = LCase(txt_expectedvalue.Value) Then

						objLog.WriteLine strComputer & ": Correct value"

					Else

						objLog.WriteLine strComputer & ": Incorrect value"

					End If

				Else

					Err.Clear

					On Error GoTo 0

					objLog.WriteLine strComputer & ": RegRead Error"

				End If

			Else

				objLog.WriteLine strComputer & ": Offline"

			End If

		Wend

		objComputersFile.Close

		objLog.Close

		MsgBox "Finished. Please see " & strLogFile

	End If

End Sub
 

Function Ping(strComputer)

	Dim objShell, boolCode

	Set objShell = CreateObject("WScript.Shell")

	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)

	If boolCode = 0 Then

		Ping = True

	Else

		Ping = False

	End If

End Function
 

</script>

 

<body>

<table width='90%' height='90%' align='center' border='0'>

	<tr>

		<td align='center' colspan="2">

			<h3>Remote Registry Check Application</h3>

		</td>

	</tr>

	<tr>

		<td>

			Computers text file:

		</td>

		<td>

			<input type="file" size="40" id="txt_textfile" name="txt_textfile">

		</td>

	</tr>

	<tr>

		<td colspan="2">

			Enter the registry path to read, including HKLM or HKCU:<br>

			(to read the "default" value, leave a backslash on the end of the path)<br>

			<input type="text" size="100" id="txt_registrypath" name="txt_registrypath">

		</td>

	</tr>

	<tr>

		<td colspan="2">

			Expected data for the above value:<br>

			<input type="text" size="100" id="txt_expectedvalue" name="txt_expectedvalue">

		</td>

	</tr>

	<tr>

		<td colspan="2">

			<button name="btn_runscript" accesskey="R" onclick="Run_Script"><u>R</u>un Script</button>

		</td>

	</tr>

</table>

</body>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 24791886
hi Rob,

Im getting a RegRead error Rob on this one.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 65

Expert Comment

by:RobSampson
ID: 24791999
Oh bugger! I just realised that none of the code I provided actually reads the remote registry!  Try this, it should now read the remote registry of each computer.

Regards,

Rob.
<head>

<title>Remote Registry Check Application</title>

<HTA:APPLICATION 

     APPLICATIONNAME="Remote Registry Check Application"

     BORDER="thin"

     SCROLL="no"

     SINGLEINSTANCE="yes"

     WINDOWSTATE="normal"

>

</head>

 

<script language="VBScript">

 

Sub Window_OnLoad

	intWidth = 800

	intHeight = 600

	Me.ResizeTo intWidth, intHeight

	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))

End Sub

 

Sub Run_Script

	If txt_textfile.Value = "" Then

		MsgBox "Please select a text file."

		txt_textfile.Focus

	ElseIf txt_registrypath.Value = "" Then

		MsgBox "Please enter a registry path."

		txt_registrypath.Focus

	Else

		Set objShell = CreateObject("WScript.Shell")

		Set objFSO = CreateObject("Scripting.FileSystemObject")

		Const intForReading = 1

	    If Mid(document.location, 6, 3) = "///" Then

	    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)

	    Else

	    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)

	    End If

		strComputersFile = txt_textfile.Value

		strLogFile = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "RegistryCheckLog.txt"

		Set objComputersFile = objFSO.OpenTextFile(strComputersFile, intForReading, False)

		Set objLog = objFSO.CreateTextFile(strLogFile, True)

		Const HKEY_LOCAL_MACHINE = &H80000002

		While Not objComputersFile.AtEndOfStream

			strComputer = objComputersFile.ReadLine

			If Ping(strComputer) = True Then

				If Right(txt_registrypath.Value, 1) = "\" Then

					strRegKey = txt_registrypath.Value

					strValue = ""

				Else

					strRegKey = Left(txt_registrypath.Value, InStrRev(txt_registrypath.Value, "\"))

					strValue = Mid(txt_registrypath.Value, InStrRev(txt_registrypath.Value, "\") + 1)

				End If

				On Error Resume Next

				Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

				objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strRegKey, strValue, strData

				If Err.Number = 0 Then

					On Error GoTo 0

					If LCase(strData) = LCase(txt_expectedvalue.Value) Then

						objLog.WriteLine strComputer & ": Correct value"

					Else

						objLog.WriteLine strComputer & ": Incorrect value"

					End If

				Else

					Err.Clear

					On Error GoTo 0

					objLog.WriteLine strComputer & ": Error reading registry"

				End If

			Else

				objLog.WriteLine strComputer & ": Offline"

			End If

		Wend

		objComputersFile.Close

		objLog.Close

		MsgBox "Finished. Please see " & strLogFile

	End If

End Sub

 

Function Ping(strComputer)

	Dim objShell, boolCode

	Set objShell = CreateObject("WScript.Shell")

	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)

	If boolCode = 0 Then

		Ping = True

	Else

		Ping = False

	End If

End Function

 

</script>

 

<body>

<table width='90%' height='90%' align='center' border='0'>

	<tr>

		<td align='center' colspan="2">

			<h3>Remote Registry Check Application</h3>

		</td>

	</tr>

	<tr>

		<td>

			Computers text file:

		</td>

		<td>

			<input type="file" size="40" id="txt_textfile" name="txt_textfile">

		</td>

	</tr>

	<tr>

		<td colspan="2">

			Enter the registry path to read, including HKLM or HKCU:<br>

			(to read the "default" value, leave a backslash on the end of the path)<br>

			<input type="text" size="100" id="txt_registrypath" name="txt_registrypath">

		</td>

	</tr>

	<tr>

		<td colspan="2">

			Expected data for the above value:<br>

			<input type="text" size="100" id="txt_expectedvalue" name="txt_expectedvalue">

		</td>

	</tr>

	<tr>

		<td colspan="2">

			<button name="btn_runscript" accesskey="R" onclick="Run_Script"><u>R</u>un Script</button>

		</td>

	</tr>

</table>

</body>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 24798499
Champion Ill test back and let you know mate :>)
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24820578
Hey mate, did you check this one out?

Rob.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 24858953
Hi Rob,
For some reason, im just getting Error reading registry on a machine it can connect to.

Here is an example:

For the text box to enter the registry path:

HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Repair\Acrobat Reader\9.0\IOD\Library

Expected data value:
C:\Program Files\Adobe\Reader 9.0\Esl\aiodlite.dll

Output:

simon-14b9608b0: Incorrect value
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 24867120
Oh, sorry...I think we don't need the HKEY_LOCAL_MACHINE on that....try this.
<head>

<title>Remote Registry Check Application</title>

<HTA:APPLICATION 

     APPLICATIONNAME="Remote Registry Check Application"

     BORDER="thin"

     SCROLL="no"

     SINGLEINSTANCE="yes"

     WINDOWSTATE="normal"

>

</head>

 

<script language="VBScript">

 

Sub Window_OnLoad

	intWidth = 800

	intHeight = 600

	Me.ResizeTo intWidth, intHeight

	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))

End Sub

 

Sub Run_Script

	If txt_textfile.Value = "" Then

		MsgBox "Please select a text file."

		txt_textfile.Focus

	ElseIf txt_registrypath.Value = "" Then

		MsgBox "Please enter a registry path."

		txt_registrypath.Focus

	Else

		Set objShell = CreateObject("WScript.Shell")

		Set objFSO = CreateObject("Scripting.FileSystemObject")

		Const intForReading = 1

	    If Mid(document.location, 6, 3) = "///" Then

	    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)

	    Else

	    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)

	    End If

		strComputersFile = txt_textfile.Value

		strLogFile = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "RegistryCheckLog.txt"

		Set objComputersFile = objFSO.OpenTextFile(strComputersFile, intForReading, False)

		Set objLog = objFSO.CreateTextFile(strLogFile, True)

		Const HKEY_LOCAL_MACHINE = &H80000002

		While Not objComputersFile.AtEndOfStream

			strComputer = objComputersFile.ReadLine

			If Ping(strComputer) = True Then

				If Right(txt_registrypath.Value, 1) = "\" Then

					strRegKey = txt_registrypath.Value

					strValue = ""

				Else

					strRegKey = Left(txt_registrypath.Value, InStrRev(txt_registrypath.Value, "\"))

					strValue = Mid(txt_registrypath.Value, InStrRev(txt_registrypath.Value, "\") + 1)

				End If

				On Error Resume Next

				Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

				objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strRegKey, strValue, strData

				If Err.Number = 0 Then

					On Error GoTo 0

					If LCase(strData) = LCase(txt_expectedvalue.Value) Then

						objLog.WriteLine strComputer & ": Correct value"

					Else

						objLog.WriteLine strComputer & ": Incorrect value"

					End If

				Else

					Err.Clear

					On Error GoTo 0

					objLog.WriteLine strComputer & ": Error reading registry"

				End If

			Else

				objLog.WriteLine strComputer & ": Offline"

			End If

		Wend

		objComputersFile.Close

		objLog.Close

		MsgBox "Finished. Please see " & strLogFile

	End If

End Sub

 

Function Ping(strComputer)

	Dim objShell, boolCode

	Set objShell = CreateObject("WScript.Shell")

	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)

	If boolCode = 0 Then

		Ping = True

	Else

		Ping = False

	End If

End Function

 

</script>

 

<body>

<table width='90%' height='90%' align='center' border='0'>

	<tr>

		<td align='center' colspan="2">

			<h3>Remote Registry Check Application</h3>

		</td>

	</tr>

	<tr>

		<td>

			Computers text file:

		</td>

		<td>

			<input type="file" size="40" id="txt_textfile" name="txt_textfile">

		</td>

	</tr>

	<tr>

		<td colspan="2">

			Enter the registry path to read, NOT including HKLM or HKCU, *ONLY* HKLM is supported:<br>

			(to read the "default" value, leave a backslash on the end of the path)<br>

			<input type="text" size="100" id="txt_registrypath" name="txt_registrypath">

		</td>

	</tr>

	<tr>

		<td colspan="2">

			Expected data for the above value:<br>

			<input type="text" size="100" id="txt_expectedvalue" name="txt_expectedvalue">

		</td>

	</tr>

	<tr>

		<td colspan="2">

			<button name="btn_runscript" accesskey="R" onclick="Run_Script"><u>R</u>un Script</button>

		</td>

	</tr>

</table>

</body>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 24913226
Thanks so much Rob...that works...sorry about the delay.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24920679
No problem. Thanks for the grade.

Rob.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now