Jump to content

How to detect windows version and install sp2?


Aero
 Share

Recommended Posts

Hey guys! I know there is a way to do this but dont have a clue where to start.

What Im trying to do is make a batch script that will install all of the official windows updates silently on an existing machine. So far i have gotten it to work for all of the post SP2 updates and everything will install just fine if SP2 is installed on the machine. Im looking for a way to tell my script to get the windows version, determine if it has SP2 installed and if it does not, give some kind of message stating that SP2 is not installed. Any ideas?

Link to comment
Share on other sites


Here a VBS script that list the Installed Hotfixes

Save as HotFixes_Installed.VBS

strComputer = "."

Dim Act, SD, Fso, Ts

Set Act = CreateObject("Wscript.Shell")

Set Fso = CreateObject("Scripting.FileSystemObject")

SD = Act.ExpandEnvironmentStrings("%Systemdrive%")

Set Ts = Fso.CreateTextFile(SD & "\Installed_HotFixes.txt")

Ts.WriteLine Space(5) & Time() & " <-----> " & Date()

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colQuickFixes = objWMIService.ExecQuery("Select * from Win32_QuickFixEngineering")

For Each objQuickFix in colQuickFixes

Ts.WriteLine "Computer: " & objQuickFix.CSName

Ts.WriteLine "Description: " & objQuickFix.Description

Ts.WriteLine "Hot Fix ID: " & objQuickFix.HotFixID

Ts.WriteLine "Installation Date: " & objQuickFix.InstallDate

Ts.WriteLine "Installed By: " & objQuickFix.InstalledBy

Next

If colQuickFixes.count = 0 Then

Ts.WriteLine "No hot fixes where found"

End If

Ts.Close

Act.Run(SD & "\Installed_HotFixes.txt"),1,True

Keep = Act.Popup("Did you want to keep the" & vbCrLf & "Installed_HotFixes.txt" &_

vbcrlf & "Yes to keep the Installed_HotFixes.txt" & vbCrLf & "No to delete the Installed_HotFixes.txt" &_

vbCrLf & "If nothing is selected in 15 seconds" & vbCrLf & "The defualt action is to keep" &_

vbCrLf & "Installed_HotFixes.txt", 15, "Keep Or Delete", 4 + 32)

If Keep = Vbyes Then

End If

If Keep = Vbno Then

Fso.DeleteFile(SD & "\Installed_HotFixes.txt")

End If

If Keep = -1 Then

End If

Edited by gunsmokingman
Link to comment
Share on other sites

What about....

@Echo Off

IF EXIST %WINDIR%\Driver~1\i386\SP2.CAB GOTO SP2YES
GOTO SP2NO

:SP2YES
SET SP2STATUS=Yes
GOTO OUTPUT

:SP2NO
SET SP2STATUS=No
GOTO OUTPUT

:OUTPUT
Cls
Echo.
Echo Does this machine have Service Pack 2 you ask?
Echo.
Echo %SP2STATUS%
Echo.
Pause
Exit

Nice and simple i know, but, does the trick....! :P

Edited by SilverBulletUK
Link to comment
Share on other sites

To see if Service Pack 2 is installed

strComputer = "."

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems

MsgBox "Confirm Service Pack " & objOperatingSystem.ServicePackMajorVersion _

& "." & objOperatingSystem.ServicePackMinorVersion & " Is Installed", 0 + 32, "Confirm SP2"

Next

If colOperatingSystems.count = 0 Then

MsgBox "Service Pack 2 Is Not Installed", 0 + 32, "Not SP2"

End If

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...