Recently I needed to take a survey of one of my clients sites to determine which service pack versions were running on the machines. As opposed to going to each pc or running some bulky software, I came across a script which will read hostnames off a text file and output the XP Service Pack versions of the machines on the network. This is a quick way to find your service pack versions of your network XP machines
To use this script you will need a list of hostnames you want to query. For this I run a simple net view and copy the hostnames from the command prompt window WITHOUT the \\. Paste the hostnames into notepad and lable it hosts.txt.
Next, copy the following into notepad
----------COPY EVERYTHING BELOW THIS LINE---------- 'List the operating system and service pack of all computers in a text file. On Error Resume Next
'Get list of computers from text file. arrComputers = ReadTextFile(strInputFile) For Each strComputer In arrComputers intGetSP = GetSP(strComputer) If 1 = intGetSP Then g_intErr = g_intErr + 1 End If Next
'Read text file line by line and return array of lines. Function ReadTextFile(strFileName)
On Error Resume Next
Dim arrLines()
Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(strFilename) Then Set objTextStream = objFSO.OpenTextFile(strFilename, FOR_READING) Else WScript.Echo "Input text file " & strFilename & " not found." WScript.Quit End If Do Until objTextStream.AtEndOfStream intLineNo = objTextStream.Line ReDim Preserve arrLines(intLineNo - 1) arrLines(intLineNo - 1) = objTextStream.ReadLine Loop objTextStream.Close ReadTextFile = arrLines
'Write or append data to text file. Sub WriteTextFile(strFileName)
On Error Resume Next
'Open text file for output. Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(strFileName) Then Set objTextStream = objFSO.OpenTextFile(strFileName, FOR_APPENDING) Else Set objTextStream = objFSO.CreateTextFile(strFileName) End If
'Write data to file. objTextStream.WriteLine "Inventory of Windows XP Service Packs" objTextStream.WriteLine "Taken " & Now objTextStream.WriteLine vbCrLf & "Computers Running Windows XP" objTextStream.WriteLine "============================" objTextStream.WriteLine "Total number: " & (g_intSP2 + g_intSP1 + g_intSP0)
objTextStream.WriteLine vbCrLf & "No Service Pack" objTextStream.WriteLine "---------------" objTextStream.WriteLine g_strSP0 objTextStream.WriteLine "Total number: " & g_intSP0
objTextStream.WriteLine vbCrLf & "Computers Not Running Windows XP" objTextStream.WriteLine "================================" objTextStream.WriteLine "Total number: " & g_intNotXP
objTextStream.WriteLine vbCrLf & "Could Not Connect To Computer" objTextStream.WriteLine "=============================" objTextStream.WriteLine "Total number: " & g_intErr objTextStream.WriteLine
objTextStream.Close
End Sub
----------COPY EVERYTHING ABOVE THIS LINE----------
Save your file as XP_Versions.vbs
Ensure that both hosts.txt and XP_Versions.vbs are in the same directory and simply run the XP_Versions.vbs. Your output will be in the same folder as the other 2 files and will be called xpsp.txt. The output will read similar to this:
-------------------------------------------------
Inventory of Windows XP Service Packs Taken 2/4/2006 12:17:09 AM
Computers Running Windows XP ============================ Total number: 2
Service Pack 2 -------------- WKS64 WKS37
Total number: 2
Service Pack 1 --------------
Total number: 0
No Service Pack ---------------
Total number: 0
Computers Not Running Windows XP ================================ Total number: 1
Could Not Connect To Computer ============================= Total number: 0
-------------------------------------------------
As you can see this script does not identify what the other machines are running and what machines are running other operating systems, it just identifies which XP computers need a service pack upgrage.
This information is provided "AS IS" with no warranties expressed or implied.