OffHand Posted August 25, 2008 Posted August 25, 2008 Hi guys,I wonder if someone could help me out with the following problem. We use a fairly simple batch script to install all the standard applications we use including XP SP3. On some computers SP3 has already been installed. I wonder if there is a way to do a version check (with the command line) and then do something like:If SP=3 ECHO Script finished please reboot nowelseWindowsXP-KB936929-SP3-x86-ENU.exe /quietThanks in advance,Martijn
Yzöwl Posted August 25, 2008 Posted August 25, 2008 Reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CSDversion|Find "Service Pack 3"||WindowsXP-KB936929-SP3-x86-ENU.exe /quiet
OffHand Posted August 25, 2008 Author Posted August 25, 2008 Reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CSDversion|Find "Service Pack 3"||WindowsXP-KB936929-SP3-x86-ENU.exe /quietThanks In human language: your code checks for SP3 on the computer and if it's not there it executes the installer? What if it's there? Sorry to bother but I need to explain to my boss what it does exactly
Yzöwl Posted August 25, 2008 Posted August 25, 2008 It queries the WinXP registry, for the string "Service Pack 3", (this is currently okay because although SP3 is in previous OSes, they don't have Reg.exe by default.) If it finds the string nothing happens, The next line, if it exists (in a script), would be executedThe double pipe effectively means 'If the previous command was unsuccessful then'.
OffHand Posted August 25, 2008 Author Posted August 25, 2008 It queries the WinXP registry, for the string "Service Pack 3", (this is currently okay because although SP3 is in previous OSes, they don't have Reg.exe by default.) If it finds the string nothing happens, The next line, if it exists (in a script), would be executedThe double pipe effectively means 'If the previous command was unsuccessful then'.TYVM. Gonna test it now. I report back in a bit!
gunsmokingman Posted August 25, 2008 Posted August 25, 2008 Here is a VBS script that checks for a service pack is installed if not installed then it will install the service pack.Save As CheckInstallSp3.vbsOption ExplicitDim Act, Fso, ColItems, ObjItem, SvcVer, Wmi Set Act = CreateObject("Wscript.Shell") Set Fso = CreateObject("Scripting.FileSystemObject") Set Wmi = GetObject("winmgmts:\\.\root\CIMV2") Set ColItems = Wmi.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48) For Each ObjItem in ColItems SvcVer = ObjItem.ServicePackMajorVersion If SvcVer = 1 Then WScript.Echo "Service Pack 1 Installed" If SvcVer = 2 Then WScript.Echo "Service Pack 2 Installed" If SvcVer = 3 Then WScript.Echo "Service Pack 3 Installed" If SvcVer = "" Then If Fso.FileExists("WindowsXP-KB936929-SP3-x86-ENU.exe") Then Act.Run(chr(34) & "WindowsXP-KB936929-SP3-x86-ENU.exe " & Chr(34) & "/quiet"),1,True WScript.Echo "Service Pack 3 Installed Has Been Completed" & _ vbCrLf & "Please Reboot The Computer To Complete" &_ vbCrLf & "The Service Pack 3 Install." Else WScript.Echo "Missing Service Pack 3" End if End If Next
OffHand Posted August 25, 2008 Author Posted August 25, 2008 (edited) The script works! Thanks again... It would be nice to make it a little more verbose. Would this be the correct way?@ECHO OFFif EXIST Reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CSDversion|Find "Service Pack 3"ECHO Service Pack 3 Already Installed. Please reboot now.elseECHO Installing Service Pack 3WindowsXP-KB936929-SP3-x86-ENU.exe /quietP.S. Thanks Gunsmoke for the VBS script suggestion but I would like to keep it a batch script Edited August 25, 2008 by OffHand
Yzöwl Posted August 25, 2008 Posted August 25, 2008 This should do it:@Echo off&SetlocalSet K_="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"Set "P_=Service Pack 3"Reg query %K_% /v CSDversion|Find "%P_%">Nul 2>&1&&( Echo:%P_% Already Installed. Please reboot now)||( Echo:Installing %P_%&WindowsXP-KB936929-SP3-x86-ENU.exe /quiet)
OffHand Posted August 25, 2008 Author Posted August 25, 2008 Thanks a lot. I will try this tomorrow and report back! Have a nice evening...
OffHand Posted August 26, 2008 Author Posted August 26, 2008 This should do it:@Echo off&SetlocalSet K_="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"Set "P_=Service Pack 3"Reg query %K_% /v CSDversion|Find "%P_%">Nul 2>&1&&( Echo:%P_% Already Installed. Please reboot now)||( Echo:Installing %P_%&WindowsXP-KB936929-SP3-x86-ENU.exe /quiet)It works. The only thing that does not work (maybe it works but the message might be gone before I can see it) is when SP3 is already installed it does not echo 'Service Pack 3 Already Installed. Please reboot now.' The script just ends. Is there a way to work around this? Maybe a pause or a command that reboots the machine after pressing a key? The later one would be ideal.
OffHand Posted August 26, 2008 Author Posted August 26, 2008 I figured it out....Set K_="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"Set "P_=Service Pack 3"Reg query %K_% /v CSDversion|Find "%P_%">Nul 2>&1&&( Echo:%P_% Already Installed. Please reboot now && ping -n 60 127.0.0.1>nul)||( Echo:Installing %P_%&WindowsXP-KB936929-SP3-x86-ENU.exe /quiet)
rdaggett Posted September 5, 2008 Posted September 5, 2008 I was wondering if anyone had a script that would report what computers were already running Service Pack 3 and create a report with those computer names.Thank you all
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now