private static extern bool GetVersionEx(ref Osversioninfoex osVersionInfo);
 private static extern bool GetVersionEx(ref Osversioninfoex osVersionInfo);
Beispiel #3
0
        public static string GetOsVersion()
        {
            var result = Err;

            var osVersionInfo = new Osversioninfoex();
            var osInfo        = Environment.OSVersion;

            osVersionInfo.dwOSVersionInfoSize =
                Marshal.SizeOf(typeof(Osversioninfoex));
            if (!GetVersionEx(ref osVersionInfo))
            {
                return(Err);
            }

            var is64 = Is64();

            Log.AppendLine("osInfo.Platform=" + osInfo.Platform);
            Log.AppendLine("osInfo.Version.Major=" + osInfo.Version.Major);
            Log.AppendLine("osInfo.Version.Minor=" + osInfo.Version.Minor);
            Log.AppendLine("osVersionInfo.wProductType=" + osVersionInfo.wProductType);
            Log.AppendLine("osVersionInfo.wSuiteMask=" + osVersionInfo.wSuiteMask);
            Log.AppendLine("IntPtr.Size=" + IntPtr.Size);
            Log.AppendLine("64 bit OS=" + Convert.ToString(is64));

            if (osInfo.Platform == PlatformID.Win32NT)
            {
                if (osInfo.Version.Major > 4)
                {
                    result = "Microsoft ";
                }

                if (osInfo.Version.Major == 6)
                {
                    if (osInfo.Version.Minor == 0)
                    {
                        if (osVersionInfo.wProductType == VerNtWorkstation)
                        {
                            result += "Windows Vista";
                        }
                        else
                        {
                            result += "Windows Server 2008";
                        }
                    }
                    else if (osInfo.Version.Minor == 1)
                    {
                        if (osVersionInfo.wProductType == VerNtWorkstation)
                        {
                            result += "Windows 7";
                        }
                        else
                        {
                            result += "Windows Server 2008 R2";
                        }
                    }
                    else if (osInfo.Version.Minor == 2)
                    {
                        if (osVersionInfo.wProductType == VerNtWorkstation)
                        {
                            result += "Windows 8";
                        }
                        else
                        {
                            result += "Windows Server 2012";
                        }
                    }
                }
                else if (osInfo.Version.Major == 5)
                {
                    if (osInfo.Version.Minor == 2)
                    {
                        if (GetSystemMetrics(SmServerr2) != 0)
                        {
                            result += "Windows Server 2003 R2";
                        }
                        else if ((osVersionInfo.wSuiteMask & VerSuiteStorageServer) > 0)
                        {
                            result += "Windows Storage Server 2003";
                        }
                        else if ((osVersionInfo.wSuiteMask & VerSuiteWhServer) > 0)
                        {
                            result += "Windows Home Server";
                        }
                        else if (osVersionInfo.wProductType == VerNtWorkstation && is64)
                        {
                            result += "Windows XP Professional x64 Edition";
                        }
                        else
                        {
                            result += "Windows Server 2003";
                        }

                        // エディション取得処理は省略
                    }
                    else if (osInfo.Version.Minor == 1)
                    {
                        result += "Windows XP";
                    }
                    else if (osInfo.Version.Minor == 0)
                    {
                        result += "Windows 2000";
                    }
                }

                // Include service pack (if any)
                if (osVersionInfo.szCSDVersion.Length > 0)
                {
                    result += " " + osVersionInfo.szCSDVersion;
                }

                // Architecture
                if (is64 == false)
                {
                    result += ", 32-bit";
                }
                else
                {
                    result += ", 64-bit";
                }
            }
            else if (osInfo.Platform == PlatformID.Win32Windows)
            {
                result = "This sample does not support this version of Windows.";
            }

            return(result);
        }