• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1479
  • Last Modified:

using OSVERSIONINFOEX wSuiteMask in VS2008 C#

I'm trying in this code to get the Os edition running on.

the return using GetOsEd is 272 when running on server 2003 standard  SP2 32bit
and 274 when running on server 2003 enterprise SP2 32bit

why don't i get the correct return codes?

public class OsInfo
    {
        [DllImport("kernel32.dll")]
        private static extern bool GetVersionEx(ref OSVERSIONINFOEX osVersionInfo);
 
        [StructLayout(LayoutKind.Sequential)]
        private struct OSVERSIONINFOEX
        {
            public int dwOSVersionInfoSize;
            public int dwMajorVersion;
            public int dwMinorVersion;
            public int dwBuildNumber;
            public int dwPlatformId;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
            public string szCSDVersion;
            public short wServicePackMajor;
            public short wServicePackMinor;
            public short wSuiteMask;
            public byte wProductType;
            public byte wReserved;
        }
 
        private const Int32 VER_SUITE_SMALLBUSINESS = 1;
        private const Int32 VER_SUITE_ENTERPRISE = 2;
        private const Int32 VER_SUITE_TERMINAL = 16;
        private const Int32 VER_SUITE_DATACENTER = 128;
        private const Int32 VER_SUITE_SINGLEUSERTS = 256;
        private const Int32 VER_SUITE_PERSONAL = 512;
        private const Int32 VER_SUITE_BLADE = 1024;
 
        public static string GetOsEd()
        {
            OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
            osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(osVersionInfo);
            GetVersionEx(ref osVersionInfo);
 
            return osVersionInfo.wSuiteMask.ToString();
        }
 
    }

Open in new window

0
OrenRozen
Asked:
OrenRozen
  • 3
  • 2
1 Solution
 
Bob LearnedCommented:
You can use the Environment class to get operating system information:

            Environment.OSVersion.Platform
            Environment.OSVersion.ServicePack
            Environment.OSVersion.Version.Major
            Environment.OSVersion.Version.Minor
            Environment.OSVersion.Version.Revision
            Environment.OSVersion.Version.Build
0
 
Bob LearnedCommented:
Reference:

How to determine the Windows version by using Visual C#
http://support.microsoft.com/kb/304283
0
 
grayeCommented:
But that *is* returning the correct mask...
274 (decimal) = 112 (hex) = which is the combination of the following SuiteMask values
VER_SUITE_SINGLEUSERTS (0x100) + VER_SUITE_TERMINAL (0x10) + VER_SUITE_ENTERPRISE (0x2)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
OrenRozenAuthor Commented:
Appreciate your fat respond.

will 274 always return for enterprise and 272 for standard?

Is there a decimal/hex table for all 2003 and 2008 edition with the
different combination's as shown in your answer?

the following link list hex values but 112 or 110 isn't in that list.
http://msdn.microsoft.com/en-us/library/ms724833(VS.85).aspx

Thanks,
0
 
grayeCommented:
So, 110 = VER_SUITE_SINGLEUSERTS (0x100) + VER_SUITE_TERMINAL (0x10).   Or, to put it another way:  0x100 + x10 = 0x110
I wouldn't bother trying to file a table of every possible value (that's 169 possible combinations)... instead I'd suggest that you "do the math" using the hex values.   That link has all of the possible values (in Hex) that can be combined together
0
 
grayeCommented:
....find a table...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now