Need a VB script to check for occurrence of XP SP3 and a patch, and take action

I need a VB script to check the registry to see if XP SP3 is on the machine, and if it is found, then the script needs to load an XP patch (.exe file).  If either XP SP3 is not on the machine OR if XP SP3 IS on the machine and the patch needed is already loaded, the script needs to exit, doing nothing to the machine.  I found the key that needs to be checked:

\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\

String name is:  CSDVersion

String value if SP3 is loaded will be "Service Pack 3"

So here's a basic summary of what this script needs to do:

1.  Check for occurrence of Service Pack 3.  If not found, END.  If found:
2.  Check for occurrence of KB953761 patch.  If found, END.  If not found:
3.  Install KB953761 patch.

Who is Participating?
Justin EllenbeckerIT DirectorCommented:
Replace line 10 with the path to where you executable is.  You should be able to use a UNC path also for the share.  This will pop up a box if the patch and SP3 are installed to remove that just place a ' in front of line 8.  Let me know if you have any questions.
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
chkkey = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CSDVersion")
sp3key = "Service Pack 3"
WScript.Echo chkkey
If chkkey = sp3key Then
	If objFSO.FolderExists("C\Windows\$NtUninstallKB953761$\") Then
		WScript.Echo "SP3 and Patch Exist no action taken"
	End If
End If

Open in new window

Justin EllenbeckerIT DirectorCommented:
Also you can delete line 5 I had that there to make sure I got the right key.  Also not sure if this KB can be uninstalled, that is how I am searching if it is there or not.  If you know of an install log or something better to search on I could put that in as well.
I'm not sure of the location of where that hotfix will show up in the registry, but you can edit the strKBPath and strKBValue variables with the correct ones if the ones I used aren't correct.  Also, the script assumes that the KB installer is in the same folder as the script.  If not, you can make that change as well.

Let me know if you have any questions.
' Script reads the value of two strings from the registry.  
'	If the first does not exist, the script exits.  If the
'	second does not exist the script excecutes an installer.

Option Explicit

Dim objShell
Dim strSP3Path, strSP3Value, strKBPath, strKBValue, strKB953761

' The path and string for SP3
strSP3Path = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
strSP3Value = "CSDVersion"
' The path and string for KB953761
strKBPath = "SOFTWARE\Microsoft\Updates\Windows XP\SP3\KB953761"
strKBValue = "Description"
' The application to be run
strKB953761 = "KB953761.exe"

' Check if SP3 exists, if it doesn't exist exit
If ReadReg (strSP3Path, strSP3Value) <> "Service Pack 3" Then Wscript.Quit

' Check if KB953761 exists, if it doesn't exist execute the file
Set objShell = CreateObject("Wscript.Shell")
If ReadReg (strKBPath, strKBValue) <> "Hotfix for Windows XP (KB953761)" Then objShell.Run strKB953761

' Script exits

Function ReadReg (KeyPath,ValueName)
	Dim objReg
	Dim strComputer, strValue, strhive

	const HKCU = &H80000001
	const HKLM = &H80000002
	strComputer = "."
	Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
	 strComputer & "\root\default:StdRegProv")	 
	' Reads the string specified and stores the value in strValue
	objReg.GetStringValue HKLM,KeyPath,ValueName,strValue
	' The function returns the value of strValue when called
	ReadReg = strValue
End Function

Open in new window

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

frankf325Author Commented:
Thanks to both of you, I will test these in the morning and get back to you, and if these solutions work...I will award points then as well.  If they don't work correctly, I'll get back to you with results of what happens and we can go from there.  Thanks for the fast response!
frankf325Author Commented:

I added the few tweaks/additions that I'd planned to add to your script above, and it worked great for what I needed to do.  The problem is...something I hadn't thought of.  We were doing this via login script to fix an issue that prevented users from mapping drives (and a few other things).  However, the thing I hadn't thought of was this:  If the users can't map drives, they can't get to the the login script either upon logging in, which makes this entire idea useless lol.  Not your fault, though, so I'm awarding points, since the script did work as it was supposed to.

Thanks again!
frankf325Author Commented:
Oh...sorry, one other thing that needed to be corrected in your script (even before I added my tweaks/add-ons)...I had to change C\Windows\$NtUninstallKB953761$\ to C:\Windows\$NtUninstallKB953761$\ (you just forgot the ":" ).  Other than that, great job!
frankf325Author Commented:
Just needed to fix a small typo from C\Windows\$NtUninstallKB953761$\ to C:\Windows\$NtUninstallKB953761$\.  The colon (":") was missing, and the script thought the patch didn't exist even when it did, but it wasn't too difficult to find that typo.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.