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

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

LVL 1
Simon336697Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
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
RobSampsonCommented:
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
Simon336697Author Commented:
As always Rob youre just over the top in a good way mate :>)
Will test and let you know :>)
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Simon336697Author 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.

0
RobSampsonCommented:
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
Simon336697Author Commented:
hi Rob,

Im getting a RegRead error Rob on this one.
0
RobSampsonCommented:
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
Simon336697Author Commented:
Champion Ill test back and let you know mate :>)
0
RobSampsonCommented:
Hey mate, did you check this one out?

Rob.
0
Simon336697Author 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
0
RobSampsonCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simon336697Author Commented:
Thanks so much Rob...that works...sorry about the delay.
0
RobSampsonCommented:
No problem. Thanks for the grade.

Rob.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.