Simon336697
asked on
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\SOFTWAR E\Microsof t\Windows\ CurrentVer sion\Insta ller\UserD ata\S-1-5- 18\Product s\90402109 00063D11C8 EF10054038 389C\Patch es\AD59682 ADCB5BCA49 86BD99DC09 5ABBE /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.
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\SOFTWAR
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
==========================
<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
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
ASKER
As always Rob youre just over the top in a good way mate :>)
Will test and let you know :>)
Will test and let you know :>)
ASKER
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\SOF TWARE\Micr osoft\Wind ows\Curren tVersion\I nstaller\U serData\S- 1-5-18\Pro ducts\9040 210900063D 11C8EF1005 4038389C\P atches\AD5 9682ADCB5B CA4986BD99 DC095ABBE\ DisplayNam e")
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.
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:
==========================
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\SOF
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.
OK, see how this goes.
Regards,
Rob.
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>
ASKER
hi Rob,
Im getting a RegRead error Rob on this one.
Im getting a RegRead error Rob on this one.
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.
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>
ASKER
Champion Ill test back and let you know mate :>)
Hey mate, did you check this one out?
Rob.
Rob.
ASKER
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\SOFTWAR E\Adobe\Re pair\Acrob at Reader\9.0\IOD\Library
Expected data value:
C:\Program Files\Adobe\Reader 9.0\Esl\aiodlite.dll
Output:
simon-14b9608b0: Incorrect value
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\SOFTWAR
Expected data value:
C:\Program Files\Adobe\Reader 9.0\Esl\aiodlite.dll
Output:
simon-14b9608b0: Incorrect value
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much Rob...that works...sorry about the delay.
No problem. Thanks for the grade.
Rob.
Rob.
Try this out. I hope I've got it right....I haven't tested it yet....
Regards,
Rob.
Open in new window