static Architecture ConvertArchitecture(NativeMethods.ProcessorArchitecture processorArchitecture) { switch (processorArchitecture) { case NativeMethods.ProcessorArchitecture.ARM64: return(Architecture.Arm64); case NativeMethods.ProcessorArchitecture.ARM: return(Architecture.Arm); case NativeMethods.ProcessorArchitecture.AMD64: return(Architecture.X64); case NativeMethods.ProcessorArchitecture.INTEL: return(Architecture.X86); default: throw new NotSupportedException( string.Format( "Processor architecture 0x{0:X} reported by Windows OS is not supported.", processorArchitecture)); } }
private void GetOSVersion() { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { NativeMethods.OSVersionInfoEx versionInfo = new NativeMethods.OSVersionInfoEx(); versionInfo.dwOSVersionInfoSize = Marshal.SizeOf(versionInfo); NativeMethods.GetVersionEx(ref versionInfo); NativeMethods.SystemInfo sysInfo = new NativeMethods.SystemInfo(); NativeMethods.GetSystemInfo(out sysInfo); NativeMethods.VersionNT versionType = (NativeMethods.VersionNT)versionInfo.wProductType; NativeMethods.ProcessorArchitecture architecture = (NativeMethods.ProcessorArchitecture)sysInfo.processorArchitecture; if (versionInfo.dwMajorVersion == 5) { if (versionInfo.dwMinorVersion == 1) { this.operatingSystemVersion = "Windows XP"; } else if (versionInfo.dwMinorVersion == 2) { int isServerR2 = NativeMethods.GetSystemMetrics((int)NativeMethods.SystemMetrics.ServerR2); if (versionType == NativeMethods.VersionNT.Workstation && architecture == NativeMethods.ProcessorArchitecture.AMD64) { this.operatingSystemVersion = "Windows XP x64 Edition"; } else if (versionType != NativeMethods.VersionNT.Workstation && isServerR2 == 0) { this.operatingSystemVersion = "Windows Server 2003"; } else if (versionType == NativeMethods.VersionNT.Workstation && isServerR2 != 0) { this.operatingSystemVersion = "Windows Server 2003 R2"; } } else { this.operatingSystemVersion = "Windows 2000"; } } else if (versionInfo.dwMajorVersion == 6) { if (versionInfo.dwMinorVersion == 0) { if (versionType == NativeMethods.VersionNT.Workstation) { this.operatingSystemVersion = "Windows Vista"; } else { this.operatingSystemVersion = "Windows Server 2008"; } } else if (versionInfo.dwMinorVersion == 1) { if (versionType == NativeMethods.VersionNT.Workstation) { this.operatingSystemVersion = "Windows 7"; } else { this.operatingSystemVersion = "Windows Server 2008 R2"; } } else { if (versionType == NativeMethods.VersionNT.Workstation) { this.operatingSystemVersion = "Windows 8"; } else { this.operatingSystemVersion = "Windows Server 2012"; } } } else { this.operatingSystemVersion = "Unsupported Windows NT version"; } if (Environment.OSVersion.ServicePack.Length > 0) { this.operatingSystemVersion = this.operatingSystemVersion + " " + Environment.OSVersion.ServicePack; } this.operatingSystemVersion += " " + string.Format(CultureInfo.InvariantCulture, "({0}.{1}.{2})", versionInfo.dwMajorVersion, versionInfo.dwMinorVersion, versionInfo.dwBuildNumber); this.operatingSystemVersion += " " + architecture.ToString().ToLowerInvariant(); } }