We help IT Professionals succeed at work.

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

Simon336697
Simon336697 asked
on
Medium Priority
582 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

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
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

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
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

Author

Commented:
As always Rob youre just over the top in a good way mate :>)
Will test and let you know :>)

Author

Commented:
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.

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
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

Author

Commented:
hi Rob,

Im getting a RegRead error Rob on this one.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
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

Author

Commented:
Champion Ill test back and let you know mate :>)
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hey mate, did you check this one out?

Rob.

Author

Commented:
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
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks so much Rob...that works...sorry about the delay.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
No problem. Thanks for the grade.

Rob.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.