Esempio n. 1
0
        public static OSName GetVersion()
        {
            OSVERSIONINFO osvi = new OSVERSIONINFO();

            osvi.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osvi);
            OSName ret;

            if (GetVersionEx(ref osvi))
            {
                if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
                {
                    #region Win32平台
                    switch (osvi.dwMajorVersion)
                    {
                    case 3:
                        ret = OSName.WinNT3;
                        break;

                    case 4:
                        ret = OSName.WinNT4;
                        break;

                    case 5:
                        switch (osvi.dwMinorVersion)
                        {
                        case 0:
                            ret = OSName.Win2000;
                            break;

                        case 1:
                            ret = OSName.WinXP;
                            break;

                        case 2:
                            ret = OSName.Win2003;
                            break;

                        default:
                            ret = OSName.UNKNOWN;
                            break;
                        }
                        break;

                    default:
                        ret = OSName.UNKNOWN;
                        break;
                    }
                    #endregion
                }
                else
                {
                    #region Win16平台
                    if (osvi.dwMajorVersion == 4)
                    {
                        //Win9X系列
                        switch (osvi.dwMinorVersion)
                        {
                        case 0:
                            ret = OSName.Win95;
                            break;

                        case 10:
                            ret = OSName.Win98;
                            break;

                        case 90:
                            ret = OSName.WinME;
                            break;

                        default:
                            ret = OSName.UNKNOWN;
                            break;
                        }
                    }
                    else
                    {
                        ret = OSName.UNKNOWN;
                    }
                    #endregion
                }
            }
            else
            {
                ret = OSName.UNKNOWN;
            }
            return(ret);
        }
Esempio n. 2
0
 public static extern bool GetVersionEx(ref OSVERSIONINFO osvi);