Detecting OS Verison and Service Pack

jsettineri
jsettineri used Ask the Experts™
on
Hi,
Does anyone know a way to detect the version of an operating system and service pack via a batch file or VB script? I have found the registry string to detect SP6a in NT4, but have not been able to put to use.
My application is: I want to allow or disallow the installation of an application depending on the OS and service pack version.  
I have tried using the "regfind" utility on NT4 resource CD, but have not had luck incorporating into "IF" statement in batch file.
Any help is greatly appreicated
Jason
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Use GetVersionEx() and specify the OSVERSIONINFOEX struct.

Commented:
shouldn't you try the programming forum?
performance engineering
Commented:
both from:
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/compmgmt/default.asp

Identify the Operating System

Returns the name and version number of the operating system installed on a computer.

Script Code


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo objOperatingSystem.Caption & " " & objOperatingSystem.Version
Next
 
Identify the Latest Installed Service Pack

Returns the last service pack to be installed on a computer.

Script Code


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo objOperatingSystem.ServicePackMajorVersion  _
        & "." & objOperatingSystem.ServicePackMinorVersion
Next
 

Author

Commented:
Thank you for your help, works great for 2k, still looking for resolution w/ NT 4.0 OS however.
Thanks for your help
Jason

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial