Tuesday, February 25, 2014

How to get OS version?

Here are steps to get OS version using C#.net code
Code line to get installed OS version string:
OperatingSystem OsInfo = Environment.OSVersion;

Steps to get Windows 95, Windows 98, Windows Me and Windows 98 Second Edition

case PlatformID.Win32Windows:
                    {
                        switch (osInfo.Version.Minor)
                        {
                            case 0:
                                {
                                    osName = "Windows 95";
                                    break;
                                }

                            case 10:
                                {
                                    if (osInfo.Version.Revision.ToString() == "2222A")
                                    {
                                        osName = "Windows 98 Second Edition";
                                    }
                                    else
                                    {
                                        osName = "Windows 98";
                                    }
                                    break;
                                }

                            case 90:
                                {
                                    osName = "Windows Me";
                                    break;
                                }
                        }
                        break;
                    }

For other versions, like XL, Windows7 and Windows8

case PlatformID.Win32NT:
                    {
                        switch (osInfo.Version.Major)
                        {
                            case 3:
                                {
                                    osName = "Windows NT 3.51";
                                    break;
                                }

                            case 4:
                                {
                                    osName = "Windows NT 4.0";
                                    break;
                                }

                            case 5:
                                {
                                    if (osInfo.Version.Minor == 0)
                                    {
                                        osName = "Windows 2000";
                                    }
                                    else if (osInfo.Version.Minor == 1)
                                    {
                                        osName = "Windows XP";
                                    }
                                    else if (osInfo.Version.Minor == 2)
                                    {
                                        osName = "Windows Server 2003";
                                    }
                                    break;
                                }

                            case 6:
                                if (osInfo.Version.Minor == 0)
                                {
                                    osName = "Windows Vista";           //6.0.x (Windows Vista)
                                }
                                else if (osInfo.Version.Minor == 1)
                                {
                                    osName = "Windows7";                //6.1.x (Windows 7 and above)
                                }
                                else
                                {
                                    osName = "Windows8";                //6.2.x (Windows 8 and above)
                                }
                                break;
                        }
                        break;

                    }

No comments:

Post a Comment