os version detection

I maintain a script in our test harness that autodetects and reports back the OS version of the machine under test.  I couldn't tell if I was running XP SP1 or XP SP2 - so I had a kludge that used spcheck from the reskit.  But the real problem was that I was getting most info using ver from the cmd shell but on Windows 2000 couldn't tell the difference between Professional and Server.  I was able to find all this info in the registry so I ripped out the hacks and now I'm just reading from there.  If anyone else out there is trying to do the same thing, here's where I get the information from (all are in HKLM):

SOFTWAREMicrosoftWindows NTCurrentVersionProductName
(Microsoft Windows Server 2003, Microsoft Windows XP, Microsoft Windows 2000)

SOFTWAREMicrosoftWindows NTCurrentVersionCDSVersion
(Service Pack 1, Service Pack 2, ...)

And to distinguish between Pro and Server on Windows 2000: SYSTEMCurrentControlSetControlProductOptionsProductType
(WinNT, ServerNT)

I didn't actually use it in my case but if you're looking for more of a prepackaged tool to do this type of thing, DtWinVer at http://www.codeproject.com/system/dtwinver.asp also looks promising. 


Comments (9)

  1. John says:

    You may also want to check out the following vbs code for the detectOSPatch function. It uses WMI:



  2. Interesting – I actually started down the WMI road but didn’t immediately find any good sample code, I’ll have to remember to give Google a push in the direction of KB articles next time. :)

    I did check out the detectOSPatch function and while it looks like it would have got me most of the way there, it still doesn’t look like it will distinguish between Windows 2000 Pro and Server since the build number for both of those is the same.

  3. KevMar says:

    Here is a clip of code that I use in one of my scripts for xml output.

    MSDN has a script-o-matic that created the sample code that this was based off of

    sub Output (value)

    WScript.Echo trim(Replace(value,"&","&"))

    end sub

    const strComputer = "."

    Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootcimv2")

    Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)

    For Each objItem in colItems

    Output "<OperatingSystem>"

    Output "<BuildNumber>" & objItem.BuildNumber & "</BuildNumber>"

    Output "<Caption>" & objItem.Caption & "</Caption>"

    Output "<CSDVersion>" & objItem.CSDVersion & "</CSDVersion>"

    Output "<Description>" & objItem.Description & "</Description>"

    Output "<SerialNumber>" & objItem.SerialNumber & "</SerialNumber>"

    Output "<ServicePackMajorVersion>" & objItem.ServicePackMajorVersion & "</ServicePackMajorVersion>"

    Output "<TotalVisibleMemorySize>" & objItem.TotalVisibleMemorySize & "</TotalVisibleMemorySize>"

    Output "</OperatingSystem>"


  4. John says:

    Yeah, its funny, google does a much better search of MS than the MS search. Maybe that will change when they release their "google search killer" ;-)

    Does the script from KevMar show the Pro vs. Server? I don’t have them handy to do a test.

  5. I could be wrong but I think KevMar’s script still just gives you the info out of the SOFTWAREMicrosoftWindows NTCurrentVersion section of the registry and not the "ProductType" that you need to distinguish.

  6. Ishai says:

    I believe that the recommended way to check OS version information is by using VerifyVersionInfo (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/verifyversioninfo.asp)

  7. very good, and that includes product type as well – thanks!

Skip to main content