views:

52

answers:

3

Hello, Can someone help me modify this code to support Windows 2003 and Windows 2008 server? Thanks

 public static string getOSLegacy()
       {
           //Get Operating system information.
           OperatingSystem os = Environment.OSVersion;
           //Get version information about the os.
           Version vs = os.Version;

           //Variable to hold our return value
           string operatingSystem = "";

           if (os.Platform == PlatformID.Win32Windows)
           {
               //This is a pre-NT version of Windows
               switch (vs.Minor)
               {
                   case 0:
                       operatingSystem = "95";
                       break;
                   case 10:
                       if (vs.Revision.ToString() == "2222A")
                           operatingSystem = "98SE";
                       else
                           operatingSystem = "98";
                       break;
                   case 90:
                       operatingSystem = "Me";
                       break;
                   default:
                       break;
               }
           }
           else if (os.Platform == PlatformID.Win32NT)
           {
               switch (vs.Major)
               {
                   case 3:
                       operatingSystem = "NT 3.51";
                       break;
                   case 4:
                       operatingSystem = "NT 4.0";
                       break;
                   case 5:
                       if (vs.Minor == 0)
                       {
                           operatingSystem = "2000";
                       }
                       else
                       {
                           operatingSystem = "XP";
                       }
                       break;
                   case 6:
                       if (vs.Minor == 0)
                       {
                           operatingSystem = "Vista";
                       }
                       else
                       {
                           operatingSystem = "7";
                       }
                       break;
                   default:
                       break;
               }
           }

           return operatingSystem;
       }
A: 

On Server 2003, Version returns 5.2.3790.131072. On Server 2008, Version returns 6.0.6002.131072.

(On Windows 7 it's 6.1.7600.0).

Also, you can get the full OS name from the registry at:

HKLM\Software\Microsoft\Windows NT\CurrentVersion, key ProductName.

BillP3rd
My 2008 returns 6.0 but I'm not running R2. It's possible that R2 is 6.1.
BillP3rd
+1  A: 

2003 is 5.2. 2008 is 6.1.

This post contains the missing pieces: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/5956c04f-072a-406c-ae6a-cc8b3a207936

umbyersw
A: 

In Win32 you use the wProductType of the OSVERSIONINFOEX to determine this. It seems strange that this information doesn't seem to be available thru .NET. Perhaps it is somewhere that I haven't found. At any rate I would be nervous about relying on version #'s to distinguish server vs. non-server operating systems.

DevinEllingson