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

LVL 3
OrenRozenAsked:
Who is Participating?
 
grayeConnect With a Mentor Commented:
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
 
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.