How to determine Windows flavor in .NET

J

Joe Cool

I did a test using the Environment.OSVersion property on various
flavors of the Windows operating system. Here are my results:

Windows 7 Ultimate x64 Microsoft Windows NT 6.1.7600.0
Vista Ultimate SP2 x64 Microsoft Windows NT 6.0.6002 Service Pack 2
Windows 7 Ultimate x86 Microsoft Windows NT 6.1.7600.0
Vista Ultimate SP2 x86 Microsoft Windows NT 6.0.6002 Service Pack 2
Windows Server Enterprise 2008 SP2 Microsoft Windows NT 6.0.6002
Service Pack 2
XP Professional SP3 Microsoft Windows NT 5.1.2500 Service Pack 3

I came to the conclusion that this property is useless for this
purpose.

Is there any way to determine this information more accurately?
 
M

Mike Lovell

I did a test using the Environment.OSVersion property on various
flavors of the Windows operating system. Here are my results:

Windows 7 Ultimate x64 Microsoft Windows NT 6.1.7600.0
Vista Ultimate SP2 x64 Microsoft Windows NT 6.0.6002 Service Pack 2
Windows 7 Ultimate x86 Microsoft Windows NT 6.1.7600.0
Vista Ultimate SP2 x86 Microsoft Windows NT 6.0.6002 Service Pack 2
Windows Server Enterprise 2008 SP2 Microsoft Windows NT 6.0.6002
Service Pack 2
XP Professional SP3 Microsoft Windows NT 5.1.2500 Service Pack 3

I came to the conclusion that this property is useless for this
purpose.

Is there any way to determine this information more accurately?

http://www.csharp411.com/determine-windows-version-and-edition-with-c/
 
A

Arne Vajhøj

I did a test using the Environment.OSVersion property on various
flavors of the Windows operating system. Here are my results:

Windows 7 Ultimate x64 Microsoft Windows NT 6.1.7600.0
Vista Ultimate SP2 x64 Microsoft Windows NT 6.0.6002 Service Pack 2
Windows 7 Ultimate x86 Microsoft Windows NT 6.1.7600.0
Vista Ultimate SP2 x86 Microsoft Windows NT 6.0.6002 Service Pack 2
Windows Server Enterprise 2008 SP2 Microsoft Windows NT 6.0.6002
Service Pack 2
XP Professional SP3 Microsoft Windows NT 5.1.2500 Service Pack 3

I came to the conclusion that this property is useless for this
purpose.

Why ?

The 5.1/6.0/6.1 is usually enough.
Is there any way to determine this information more accurately?

You can check what is available via WMI.

Small example:

using System;
using System.Management;

namespace E
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(Environment.OSVersion);
ObjectQuery wmios = new WqlObjectQuery("SELECT * FROM
Win32_OperatingSystem");
ManagementObjectSearcher oss = new
ManagementObjectSearcher(wmios);
foreach (ManagementObject os in oss.Get())
{
Console.WriteLine(os["Caption"]);
}
Console.ReadKey();
}
}
}

See other items her:
http://msdn.microsoft.com/en-us/library/aa394239(VS.85).aspx

Arne
 
J

Joe Cool


Every OS reports that is Windows NT. I would to know if it is Windows
7, Vista or XP.
The 5.1/6.0/6.1 is usually enough.
Is there any way to determine this information more accurately?

You can check what is available via WMI.

Small example:

using System;
using System.Management;

namespace E
{
     public class Program
     {
         public static void Main(string[] args)
         {
             Console.WriteLine(Environment.OSVersion);
             ObjectQuery wmios = new WqlObjectQuery("SELECT * FROM
Win32_OperatingSystem");
             ManagementObjectSearcher oss =  new
ManagementObjectSearcher(wmios);
             foreach (ManagementObject os in oss.Get())
             {
                 Console.WriteLine(os["Caption"]);
             }
             Console.ReadKey();
         }
     }

}

See other items her:
   http://msdn.microsoft.com/en-us/library/aa394239(VS.85).aspx
 
A

Arne Vajhøj

I have ran an initial test of this code and it appears to not be
completely up to date. When run on Windows 7 it says it is Vista.

If you just need that info, then Environment.OSVersion is fine.

If you need the Ultimate/Enterprise/whatever info, then you
may need to use WMI.

See the code example that I posted.

Arne
 
J

Joe Cool

I have ran an initial test of this code and it appears to not be
completely up to date. When run on Windows 7 it says it is Vista.

I have updated the class to be able to make this determination. I like
the way this returns the Edition, ie Ultimate,etc, and the bits, 32 or
64.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top