Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect Vista edition using Win32_OperatingSystem

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
I am trying to write code that will allow me to detect precisely what edition of Windows Vista I am running under (e.g. "Home Basic", "Home Premium" etc). The old code I used for XP and earlier does not go far enough (Sysinfo control and GetVersionEx API call).

The option with the best potential appears to be the OperatingSystemSKU property of the Win32_OperatingSystem WMI class . This code works:
Code:
Dim objOS As Object
For Each objOS In GetObject( _
    "winmgmts:").InstancesOf("Win32_OperatingSystem")

  MsgBox "Caption = " & objOS.Caption & vbCr _
       & "Version = " & objOS.Version & vbCr _
       & "Name = " & objOS.Name & vbCr _
       & "Creation Class = " & objOS.CreationClassName & vbCr _
       & "Type = " & objOS.ostype & vbCr _
       & "Registered User = " & objOS.RegisteredUser & vbCr _
       & "System device = " & objOS.SystemDevice & vbCr _
       & "Install Date = " & objOS.InstallDate & vbCr _
       & "Manufacturer = " & objOS.Manufacturer
'      If .dwMajorVersion >= 6 Then
       If objOS.Version >= "6" Then
         MsgBox "Vista flavour is " & objOS.OperatingSystemSKU
       End If
Next
The problem is that, if there are multiple operating systems installed, this will loop through the lot. What I need to be able to do is identify the operating system instance that I am running from and process only that instance.

Any help would be greatly nappreciated.
 
One thought I have now had....

Might it be safe to make 2 assumptions:

a) that, if the class's .NumberOfProcesses property is non-zero then the associated operating system instance is running
b) that 2 operating systems cannot run concurrently

If this is the case, I have then identified the instance I am running within.

Of course, tools like Virtual PC allows one operating system to run 'within' another but such instances of the operating system are not detected by this logic.
(though I may need to investigate what happens in a virtual PC environment).
 
Read up on GetVersionEx, which will direct you to [tt]GetProductInfo[/tt] for OSs at versions 6.0 and later.

Lots of other good comments there as well.

WMI can do it, but WMI is the long way around to get the same info and won't work if the WMI service isn't running.
 
Thanks.

I have been using GetversionEx up until now to get Windows XP and service pack info. I did come across GetProductInfo (it's what pushed me towards Win32_OperatingSystem) but noted that it required Windows Vista and I need the application to continue to work under XP. I wasn't sure of the implications of trying to compile under XP.
 
I'm not aware of a circumstance under which operating systems can run concurrently in the PC world. Although there are circumstances that give that functionality, the actual goings on are that one operating system is hosting the other as a guest.
 
OK thanks - neither am I! In the absence of a better idea I have taken the approach suggested in my second post.
 
Glasgow said:
I wasn't sure of the implications of trying to compile under XP

Old thread I know, but for anyone else who comes across it:

GetProductInfo compiles and runs okay under XP (I had a play with it yesterday).

I'm using a GetProductInfo call to return futher OS information once I've established that the OS is Vista / Longhorn using the dwMajorVersion returned from a GetVersionEx call.

TazUk

Programmer An organism that turns coffee into software. [morning]
Unknown Author
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top