Solved

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

Posted on 2009-07-05
13
562 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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