Help - Search - Members - Calendar
Full Version: Batch File XP Service Pack Version Check
MSFN Forums > Coding, Scripting and Servers > Programming (C++, Delphi, VB, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
OffHand
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 now
else
WindowsXP-KB936929-SP3-x86-ENU.exe /quiet

Thanks in advance,
Martijn
Yzöwl
CODE
Reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CSDversion|Find "Service Pack 3"||WindowsXP-KB936929-SP3-x86-ENU.exe /quiet
OffHand
QUOTE (Yzöwl @ Aug 25 2008, 01:30 PM) *
CODE
Reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CSDversion|Find "Service Pack 3"||WindowsXP-KB936929-SP3-x86-ENU.exe /quiet

Thanks smile.gif

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 newwink.gif
Yzöwl
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 executed
The double pipe effectively means 'If the previous command was unsuccessful then'.
OffHand
QUOTE (Yzöwl @ Aug 25 2008, 01:45 PM) *
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 executed
The double pipe effectively means 'If the previous command was unsuccessful then'.

TYVM. Gonna test it now. I report back in a bit!
gunsmokingman
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.vbs

QUOTE
CODE
Option Explicit
Dim 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
The script works! Thanks again... It would be nice to make it a little more verbose.

Would this be the correct way?

@ECHO OFF

if EXIST Reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CSDversion|Find "Service Pack 3"
ECHO Service Pack 3 Already Installed. Please reboot now.
else
ECHO Installing Service Pack 3
WindowsXP-KB936929-SP3-x86-ENU.exe /quiet

P.S. Thanks Gunsmoke for the VBS script suggestion but I would like to keep it a batch script smile.gif
Yzöwl
This should do it:
CODE
@Echo off&Setlocal
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)||(
  Echo:Installing %P_%&WindowsXP-KB936929-SP3-x86-ENU.exe /quiet)
OffHand
Thanks a lot. I will try this tomorrow and report back! Have a nice evening...
OffHand
QUOTE (Yzöwl @ Aug 25 2008, 06:10 PM) *
This should do it:
CODE
@Echo off&Setlocal
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)||(
  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
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
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
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.