Script Center >
Scripting Forums
>
The Official Scripting Guys Forum!
>
Check OS, Check Hotfix, Install if not present
Check OS, Check Hotfix, Install if not present
- Hi all,
This may seem like a simple question, but Scripting is not my forte.
I'm trying to figure out a way to check that the client OS is XPsp3 and then look for the existence of the $NTUninstallKB953760$ folder, and if it is not present, to install \\server\share\WindowsXP-kb953760-x86-ENU.exe.
Any assistance or advice would be greatly appreciated.
Thanks, Mark
Answers
- Hi Mark,
I modified your script a bit to check for whether the patch is installed instead of checking for the uninstall folder.
1 Set objShell = CreateObject("WScript.Shell") 2 Set objFSO = CreateObject("Scripting.FileSystemObject") 3 4 strComputer = "." 5 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 6 Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Name LIKE '%Microsoft Windows XP%'") 7 For Each objItem In colItems 8 If objItem.CSDVersion = "Service Pack 3" Then 9 If CheckPatch("KB953760")=True then 10 Wscript.Echo "Patch found." 11 Else 12 Wscript.Echo "Patch not found. Installing patch..." 13 objShell.Run "\\server\share\WindowsXP-kb953760-x86-ENU.exe /qn", ,TRUE 14 End if 15 End If 16 Next 17 18 Function CheckPatch(patch) 19 Set objSession = CreateObject("Microsoft.Update.Session") 20 Set objSearcher = objSession.CreateUpdateSearcher 21 Set objResults = objSearcher.Search("Type='Software'") 22 Set colUpdates = objResults.Updates 23 Found = False 24 Result = 0 25 For i = 0 to colUpdates.Count - 1 26 Result = Instr(colUpdates.Item(i).Title, patch) 27 If Result > 0 then 28 Found = True 29 Exit For 30 End if 31 Next 32 CheckPatch = Found 33 End Function
Regards,
Salvador Manaois III
MCSE MCSA CEH MCITP | Enterprise/Server Admin
Bytes & Badz : http://badzmanaois.blogspot.com- Marked As Answer byMark A. Wilson Wednesday, October 22, 2008 3:54 PM
All Replies
- Hey Mark,
Give this a try:Set objShell = CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Name LIKE '%Microsoft Windows XP%'") For Each objItem In colItems If objItem.CSDVersion = "Service Pack 3" Then If objFSO.FolderExists("C:\WINDOWS\$NTUninstallKB953760$")=False Then objShell.Run "\\server\share\WindowsXP-kb953760-x86-ENU.exe /qn", ,TRUE End If End If Next
-N
- nckmrtn said:
Hey Mark,
Give this a try:
Set objShell = CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Name LIKE '%Microsoft Windows XP%'") For Each objItem In colItems If objItem.CSDVersion = "Service Pack 3" Then' YES XP has SP3, then we check for patch If objFSO.FolderExists("C:\WINDOWS\$NTUninstallKB953760$")=False Then'Nope patch is not here, lets install on next line objShell.Run "\\server\share\WindowsXP-kb953760-x86-ENU.exe /qn", ,TRUE'Install patch from share End If End If Next
-N
Put some small "helpers" in the script wich by itself is doing the job.
Checks for SP3 & the actual hotfix. - Hi Mark,
I modified your script a bit to check for whether the patch is installed instead of checking for the uninstall folder.
1 Set objShell = CreateObject("WScript.Shell") 2 Set objFSO = CreateObject("Scripting.FileSystemObject") 3 4 strComputer = "." 5 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 6 Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Name LIKE '%Microsoft Windows XP%'") 7 For Each objItem In colItems 8 If objItem.CSDVersion = "Service Pack 3" Then 9 If CheckPatch("KB953760")=True then 10 Wscript.Echo "Patch found." 11 Else 12 Wscript.Echo "Patch not found. Installing patch..." 13 objShell.Run "\\server\share\WindowsXP-kb953760-x86-ENU.exe /qn", ,TRUE 14 End if 15 End If 16 Next 17 18 Function CheckPatch(patch) 19 Set objSession = CreateObject("Microsoft.Update.Session") 20 Set objSearcher = objSession.CreateUpdateSearcher 21 Set objResults = objSearcher.Search("Type='Software'") 22 Set colUpdates = objResults.Updates 23 Found = False 24 Result = 0 25 For i = 0 to colUpdates.Count - 1 26 Result = Instr(colUpdates.Item(i).Title, patch) 27 If Result > 0 then 28 Found = True 29 Exit For 30 End if 31 Next 32 CheckPatch = Found 33 End Function
Regards,
Salvador Manaois III
MCSE MCSA CEH MCITP | Enterprise/Server Admin
Bytes & Badz : http://badzmanaois.blogspot.com- Marked As Answer byMark A. Wilson Wednesday, October 22, 2008 3:54 PM
- Thanks so much for your assistance guys!
- Any way to run this against remote computers where the person logged on is only in the users group?
- Not possible as the script is installing an OS patch; non-admins will not be able to accomplish this task. Use WSUS if you want to install patches on your clients without explicitly granting users admin rights on their machines.
http://technet.microsoft.com/en-us/wsus/default.aspx
Regards,
Salvador Manaois III
MCSE MCSA CEH MCITP | Enterprise/Server Admin
Bytes & Badz : http://badzmanaois.blogspot.com

