Jump to content

Batch File XP Service Pack Version Check


Recommended Posts

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

Link to comment
Share on other sites


Reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CSDversion|Find "Service Pack 3"||WindowsXP-KB936929-SP3-x86-ENU.exe /quiet

Thanks :)

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 ;)

Link to comment
Share on other sites

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'.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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 :)

Edited by OffHand
Link to comment
Share on other sites

This should do it:

@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)

Link to comment
Share on other sites

This should do it:
@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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...