string getOSInfo()
{
//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 if (vs.Minor == 1)
operatingSystem = "7";
else if (vs.Minor == 2)
operatingSystem = "8";
else
operatingSystem = "8.1";
break;
case 10:
operatingSystem = "10";
break;
default:
break;
}
}
//Make sure we actually got something in our OS check
//We don't want to just return " Service Pack 2" or " 32-bit"
//That information is useless without the OS version.
if (operatingSystem != "")
{
//Got something. Let's prepend "Windows" and get more info.
operatingSystem = "Windows " + operatingSystem;
//See if there's a service pack installed.
if (os.ServicePack != "")
{
//Append it to the OS name. i.e. "Windows XP Service Pack 3"
operatingSystem += " " + os.ServicePack;
}
//Append the OS architecture. i.e. "Windows XP Service Pack 3 32-bit"
//operatingSystem += " " + getOSArchitecture().ToString() + "-bit";
}
//Return the information we've gathered.
return operatingSystem;
}
using System;
using System.Runtime.InteropServices;
/// <summary>
/// Provides detailed information about the host operating system.
/// </summary>
public static class OSInfo
{
#region BITS
/// <summary>
/// Determines if the current application is 32 or 64-bit.
/// </summary>
public static int Bits
{
get
{
return IntPtr.Size * 8;
}
}
#endregion BITS
#region EDITION
private static string s_Edition;
/// <summary>
/// Gets the edition of the operating system running on this computer.
/// </summary>
public static string Edition
{
get
{
if (s_Edition != null)
return s_Edition; //***** RETURN *****//
string edition = String.Empty;
OperatingSystem osVersion = Environment.OSVersion;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf( typeof( OSVERSIONINFOEX ) );
if (GetVersionEx( ref osVersionInfo ))
{
int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor;
byte productType = osVersionInfo.wProductType;
short suiteMask = osVersionInfo.wSuiteMask;
#region VERSION 4
if (majorVersion == 4)
{
if (productType == VER_NT_WORKSTATION)
{
// Windows NT 4.0 Workstation
edition = "Workstation";
}
else if (productType == VER_NT_SERVER)
{
if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
// Windows NT 4.0 Server Enterprise
edition = "Enterprise Server";
}
else
{
// Windows NT 4.0 Server
edition = "Standard Server";
}
}
}
#endregion VERSION 4
#region VERSION 5
else if (majorVersion == 5)
{
if (productType == VER_NT_WORKSTATION)
{
if ((suiteMask & VER_SUITE_PERSONAL) != 0)
{
// Windows XP Home Edition
edition = "Home";
}
else
{
// Windows XP / Windows 2000 Professional
edition = "Professional";
}
}
else if (productType == VER_NT_SERVER)
{
if (minorVersion == 0)
{
if ((suiteMask & VER_SUITE_DATACENTER) != 0)
{
// Windows 2000 Datacenter Server
edition = "Datacenter Server";
}
else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
// Windows 2000 Advanced Server
edition = "Advanced Server";
}
else
{
// Windows 2000 Server
edition = "Server";
}
}
else
{
if ((suiteMask & VER_SUITE_DATACENTER) != 0)
{
// Windows Server 2003 Datacenter Edition
edition = "Datacenter";
}
else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
{
// Windows Server 2003 Enterprise Edition
edition = "Enterprise";
}
else if ((suiteMask & VER_SUITE_BLADE) != 0)
{
// Windows Server 2003 Web Edition
edition = "Web Edition";
}
else
{
// Windows Server 2003 Standard Edition
edition = "Standard";
}
}
}
}
#endregion VERSION 5
#region VERSION 6
else if (majorVersion == 6)
{
int ed;
if (GetProductInfo( majorVersion, minorVersion,
osVersionInfo.wServicePackMajor, osVersionInfo.wServicePackMinor,
out ed ))
{
switch (ed)
{
case PRODUCT_BUSINESS:
edition = "Business";
break;
case PRODUCT_BUSINESS_N:
edition = "Business N";
break;
case PRODUCT_CLUSTER_SERVER:
edition = "HPC Edition";
break;
case PRODUCT_DATACENTER_SERVER:
edition = "Datacenter Server";
break;
case PRODUCT_DATACENTER_SERVER_CORE:
edition = "Datacenter Server (core installation)";
break;
case PRODUCT_ENTERPRISE:
edition = "Enterprise";
break;
case PRODUCT_ENTERPRISE_N:
edition = "Enterprise N";
break;
case PRODUCT_ENTERPRISE_SERVER:
edition = "Enterprise Server";
break;
case PRODUCT_ENTERPRISE_SERVER_CORE:
edition = "Enterprise Server (core installation)";
break;
case PRODUCT_ENTERPRISE_SERVER_CORE_V:
edition = "Enterprise Server without Hyper-V (core installation)";
break;
case PRODUCT_ENTERPRISE_SERVER_IA64:
edition = "Enterprise Server for Itanium-based Systems";
break;
case PRODUCT_ENTERPRISE_SERVER_V:
edition = "Enterprise Server without Hyper-V";
break;
case PRODUCT_HOME_BASIC:
edition = "Home Basic";
break;
case PRODUCT_HOME_BASIC_N:
edition = "Home Basic N";
break;
case PRODUCT_HOME_PREMIUM:
edition = "Home Premium";
break;
case PRODUCT_HOME_PREMIUM_N:
edition = "Home Premium N";
break;
case PRODUCT_HYPERV:
edition = "Microsoft Hyper-V Server";
break;
case PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT:
edition = "Windows Essential Business Management Server";
break;
case PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING:
edition = "Windows Essential Business Messaging Server";
break;
case PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY:
edition = "Windows Essential Business Security Server";
break;
case PRODUCT_SERVER_FOR_SMALLBUSINESS:
edition = "Windows Essential Server Solutions";
break;
case PRODUCT_SERVER_FOR_SMALLBUSINESS_V:
edition = "Windows Essential Server Solutions without Hyper-V";
break;
case PRODUCT_SMALLBUSINESS_SERVER:
edition = "Windows Small Business Server";
break;
case PRODUCT_STANDARD_SERVER:
edition = "Standard Server";
break;
case PRODUCT_STANDARD_SERVER_CORE:
edition = "Standard Server (core installation)";
break;
case PRODUCT_STANDARD_SERVER_CORE_V:
edition = "Standard Server without Hyper-V (core installation)";
break;
case PRODUCT_STANDARD_SERVER_V:
edition = "Standard Server without Hyper-V";
break;
case PRODUCT_STARTER:
edition = "Starter";
break;
case PRODUCT_STORAGE_ENTERPRISE_SERVER:
edition = "Enterprise Storage Server";
break;
case PRODUCT_STORAGE_EXPRESS_SERVER:
edition = "Express Storage Server";
break;
case PRODUCT_STORAGE_STANDARD_SERVER:
edition = "Standard Storage Server";
break;
case PRODUCT_STORAGE_WORKGROUP_SERVER:
edition = "Workgroup Storage Server";
break;
case PRODUCT_UNDEFINED:
edition = "Unknown product";
break;
case PRODUCT_ULTIMATE:
edition = "Ultimate";
break;
case PRODUCT_ULTIMATE_N:
edition = "Ultimate N";
break;
case PRODUCT_WEB_SERVER:
edition = "Web Server";
break;
case PRODUCT_WEB_SERVER_CORE:
edition = "Web Server (core installation)";
break;
}
}
}
#endregion VERSION 6
}
s_Edition = edition;
return edition;
}
}
#endregion EDITION
#region NAME
private static string s_Name;
/// <summary>
/// Gets the name of the operating system running on this computer.
/// </summary>
public static string Name
{
get
{
if (s_Name != null)
return s_Name; //***** RETURN *****//
string name = "unknown";
OperatingSystem osVersion = Environment.OSVersion;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf( typeof( OSVERSIONINFOEX ) );
if (GetVersionEx( ref osVersionInfo ))
{
int majorVersion = osVersion.Version.Major;
int minorVersion = osVersion.Version.Minor;
switch (osVersion.Platform)
{
case PlatformID.Win32Windows:
{
if (majorVersion == 4)
{
string csdVersion = osVersionInfo.szCSDVersion;
switch (minorVersion)
{
case 0:
if (csdVersion == "B" || csdVersion == "C")
name = "Windows 95 OSR2";
else
name = "Windows 95";
break;
case 10:
if (csdVersion == "A")
name = "Windows 98 Second Edition";
else
name = "Windows 98";
break;
case 90:
name = "Windows Me";
break;
}
}
break;
}
case PlatformID.Win32NT:
{
byte productType = osVersionInfo.wProductType;
switch (majorVersion)
{
case 3:
name = "Windows NT 3.51";
break;
case 4:
switch (productType)
{
case 1:
name = "Windows NT 4.0";
break;
case 3:
name = "Windows NT 4.0 Server";
break;
}
break;
case 5:
switch (minorVersion)
{
case 0:
name = "Windows 2000";
break;
case 1:
name = "Windows XP";
break;
case 2:
name = "Windows Server 2003";
break;
}
break;
case 6:
switch (productType)
{
case 1:
name = "Windows Vista";
break;
case 3:
name = "Windows Server 2008";
break;
}
break;
}
break;
}
}
}
s_Name = name;
return name;
}
}
#endregion NAME
#region PINVOKE
#region GET
#region PRODUCT INFO
[DllImport( "Kernel32.dll" )]
internal static extern bool GetProductInfo(
int osMajorVersion,
int osMinorVersion,
int spMajorVersion,
int spMinorVersion,
out int edition );
#endregion PRODUCT INFO
#region VERSION
[DllImport( "kernel32.dll" )]
private static extern bool GetVersionEx( ref OSVERSIONINFOEX osVersionInfo );
#endregion VERSION
#endregion GET
#region OSVERSIONINFOEX
[StructLayout( LayoutKind.Sequential )]
private struct OSVERSIONINFOEX
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 128 )]
public string szCSDVersion;
public short wServicePackMajor;
public short wServicePackMinor;
public short wSuiteMask;
public byte wProductType;
public byte wReserved;
}
#endregion OSVERSIONINFOEX
#region PRODUCT
private const int PRODUCT_UNDEFINED = 0x00000000;
private const int PRODUCT_ULTIMATE = 0x00000001;
private const int PRODUCT_HOME_BASIC = 0x00000002;
private const int PRODUCT_HOME_PREMIUM = 0x00000003;
private const int PRODUCT_ENTERPRISE = 0x00000004;
private const int PRODUCT_HOME_BASIC_N = 0x00000005;
private const int PRODUCT_BUSINESS = 0x00000006;
private const int PRODUCT_STANDARD_SERVER = 0x00000007;
private const int PRODUCT_DATACENTER_SERVER = 0x00000008;
private const int PRODUCT_SMALLBUSINESS_SERVER = 0x00000009;
private const int PRODUCT_ENTERPRISE_SERVER = 0x0000000A;
private const int PRODUCT_STARTER = 0x0000000B;
private const int PRODUCT_DATACENTER_SERVER_CORE = 0x0000000C;
private const int PRODUCT_STANDARD_SERVER_CORE = 0x0000000D;
private const int PRODUCT_ENTERPRISE_SERVER_CORE = 0x0000000E;
private const int PRODUCT_ENTERPRISE_SERVER_IA64 = 0x0000000F;
private const int PRODUCT_BUSINESS_N = 0x00000010;
private const int PRODUCT_WEB_SERVER = 0x00000011;
private const int PRODUCT_CLUSTER_SERVER = 0x00000012;
private const int PRODUCT_HOME_SERVER = 0x00000013;
private const int PRODUCT_STORAGE_EXPRESS_SERVER = 0x00000014;
private const int PRODUCT_STORAGE_STANDARD_SERVER = 0x00000015;
private const int PRODUCT_STORAGE_WORKGROUP_SERVER = 0x00000016;
private const int PRODUCT_STORAGE_ENTERPRISE_SERVER = 0x00000017;
private const int PRODUCT_SERVER_FOR_SMALLBUSINESS = 0x00000018;
private const int PRODUCT_SMALLBUSINESS_SERVER_PREMIUM = 0x00000019;
private const int PRODUCT_HOME_PREMIUM_N = 0x0000001A;
private const int PRODUCT_ENTERPRISE_N = 0x0000001B;
private const int PRODUCT_ULTIMATE_N = 0x0000001C;
private const int PRODUCT_WEB_SERVER_CORE = 0x0000001D;
private const int PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT = 0x0000001E;
private const int PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY = 0x0000001F;
private const int PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING = 0x00000020;
private const int PRODUCT_SERVER_FOR_SMALLBUSINESS_V = 0x00000023;
private const int PRODUCT_STANDARD_SERVER_V = 0x00000024;
private const int PRODUCT_ENTERPRISE_SERVER_V = 0x00000026;
private const int PRODUCT_STANDARD_SERVER_CORE_V = 0x00000028;
private const int PRODUCT_ENTERPRISE_SERVER_CORE_V = 0x00000029;
private const int PRODUCT_HYPERV = 0x0000002A;
#endregion PRODUCT
#region VERSIONS
private const int VER_NT_WORKSTATION = 1;
private const int VER_NT_DOMAIN_CONTROLLER = 2;
private const int VER_NT_SERVER = 3;
private const int VER_SUITE_SMALLBUSINESS = 1;
private const int VER_SUITE_ENTERPRISE = 2;
private const int VER_SUITE_TERMINAL = 16;
private const int VER_SUITE_DATACENTER = 128;
private const int VER_SUITE_SINGLEUSERTS = 256;
private const int VER_SUITE_PERSONAL = 512;
private const int VER_SUITE_BLADE = 1024;
#endregion VERSIONS
#endregion PINVOKE
#region SERVICE PACK
/// <summary>
/// Gets the service pack information of the operating system running on this computer.
/// </summary>
public static string ServicePack
{
get
{
string servicePack = String.Empty;
OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf( typeof( OSVERSIONINFOEX ) );
if (GetVersionEx( ref osVersionInfo ))
{
servicePack = osVersionInfo.szCSDVersion;
}
return servicePack;
}
}
#endregion SERVICE PACK
#region VERSION
#region BUILD
/// <summary>
/// Gets the build version number of the operating system running on this computer.
/// </summary>
public static int BuildVersion
{
get
{
return Environment.OSVersion.Version.Build;
}
}
#endregion BUILD
#region FULL
#region STRING
/// <summary>
/// Gets the full version string of the operating system running on this computer.
/// </summary>
public static string VersionString
{
get
{
return Environment.OSVersion.Version.ToString();
}
}
#endregion STRING
#region VERSION
/// <summary>
/// Gets the full version of the operating system running on this computer.
/// </summary>
public static Version Version
{
get
{
return Environment.OSVersion.Version;
}
}
#endregion VERSION
#endregion FULL
#region MAJOR
/// <summary>
/// Gets the major version number of the operating system running on this computer.
/// </summary>
public static int MajorVersion
{
get
{
return Environment.OSVersion.Version.Major;
}
}
#endregion MAJOR
#region MINOR
/// <summary>
/// Gets the minor version number of the operating system running on this computer.
/// </summary>
public static int MinorVersion
{
get
{
return Environment.OSVersion.Version.Minor;
}
}
#endregion MINOR
#region REVISION
/// <summary>
/// Gets the revision version number of the operating system running on this computer.
/// </summary>
public static int RevisionVersion
{
get
{
return Environment.OSVersion.Version.Revision;
}
}
#endregion REVISION
#endregion VERSION
}
string osVer = System.Environment.OSVersion.Version.ToString();
if (osVer.StartsWith("5")) // windows 2000, xp win2k3
{
MessageBox.Show("xp!");
}
else // windows vista and windows 7 start with 6 in the version #
{
MessageBox.Show("Win7!");
}
public static string OS_Name()
{
return (string)(from x in new ManagementObjectSearcher(
"SELECT Caption FROM Win32_OperatingSystem").Get().Cast<ManagementObject>()
select x.GetPropertyValue("Caption")).FirstOrDefault();
}
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
然后你可以这样使用 Environment.OSVersion:
var version = Environment.OSVersion;
Console.WriteLine(version);
// Before: Microsoft Windows NT 6.2.9200.0
// After: Microsoft Windows NT 10.0.19044.0
var versionString = (string)Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion")?.GetValue("productName");
class Windows
{
public class Info
{
public string Name = "";
public string fullName = "";
public string UserAgent = "";
public string Type = "";
public string codeName = "";
public string Version = "";
public string buildNumber = "";
}
public static Info GetInfo()
{
string HKLMWinNTCurrent = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion";
string osBuild = Registry.GetValue(HKLMWinNTCurrent, "CurrentBuildNumber", "").ToString();
string fullName = Registry.GetValue(HKLMWinNTCurrent, "productName", "").ToString();
string Type = Environment.Is64BitOperatingSystem ? "x64" : "x84";
string win11 = "Windows 11 version 21H2";
string win10 = "Windows 10 version ";
string win81 = "Windows 8.1";
string win8 = "Windows 8";
string win7 = "Windows 7";
string winVista = "Windows Vista";
string winXP = "Windows XP";
string winMe = "Windows Me";
string win98 = "Windows 98";
string win98_2 = "Windows 98 Second Edition";
string win2000 = "Windows 2000";
string v11 = "Windows NT 11";
string v10 = "Windows NT 10";
string v81 = "Windows NT 6.3";
string v8 = "Windows NT 6.2";
string v7 = "Windows NT 6.1";
string vVista = "Windows NT 6.0";
string vXP1 = "Windows NT 5.2";
string vXP = "Windows NT 5.1";
string vMe = "Windows NT 4.9";
string v98 = "Windows NT 4.1";
string v2000 = "Windows NT 5.0";
switch (osBuild)
{
case "22000":
return new Info()
{
Name = win11,
Version = "21H2",
UserAgent = v11,
buildNumber = "22000",
codeName = "Sun Valley",
fullName = fullName,
Type = Type
};
case "19044":
return new Info()
{
Name = win10 + "21H2",
Version = "21H2",
UserAgent = v10,
buildNumber = "19044",
codeName = "Vibranium",
fullName = fullName,
Type = Type
};
case "19043":
return new Info()
{
Name = win10 + "21H1",
Version = "21H1",
UserAgent = v10,
buildNumber = "19043",
codeName = "Vibranium",
fullName = fullName,
Type = Type
};
case "19042":
return new Info()
{
Name = win10 + "20H2",
Version = "20H2",
UserAgent = v10,
buildNumber = "19042",
codeName = "Vibranium",
fullName = fullName,
Type = Type
};
case "19041":
return new Info()
{
Name = win10 + "2004",
Version = "2004",
UserAgent = v10,
buildNumber = "19041",
codeName = "Vibranium",
fullName = fullName,
Type = Type
};
case "18363":
return new Info()
{
Name = win10 + "1909",
Version = "1909",
UserAgent = v10,
buildNumber = "18363",
codeName = "Vibranium",
fullName = fullName,
Type = Type
};
case "18362":
return new Info()
{
Name = win10 + "1903",
Version = "1903",
UserAgent = v10,
buildNumber = "18362",
codeName = "19H1",
fullName = fullName,
Type = Type
};
case "17763":
return new Info()
{
Name = win10 + "1809",
Version = "1809",
UserAgent = v10,
buildNumber = "17763",
codeName = "Redstone 5",
fullName = fullName,
Type = Type
};
case "17134":
return new Info()
{
Name = win10 + "1803",
Version = "1803",
UserAgent = v10,
buildNumber = "17134",
codeName = "Redstone 4",
fullName = fullName,
Type = Type
};
case "16299":
return new Info()
{
Name = win10 + "1709",
Version = "1709",
UserAgent = v10,
buildNumber = "16299",
codeName = "Redstone 3",
fullName = fullName,
Type = Type
};
case "15063":
return new Info()
{
Name = win10 + "1703",
Version = "1703",
UserAgent = v10,
buildNumber = "15063",
codeName = "Redstone 2",
fullName = fullName,
Type = Type
};
case "14393":
return new Info()
{
Name = win10 + "1607",
Version = "1607",
UserAgent = v10,
buildNumber = "14393",
codeName = "Redstone 1",
fullName = fullName,
Type = Type
};
case "10586":
return new Info()
{
Name = win10 + "1511",
Version = "1511",
UserAgent = v10,
buildNumber = "10586",
codeName = "Threshold 2",
fullName = fullName,
Type = Type
};
case "10240":
return new Info()
{
Name = win10 + "1507",
Version = "NT 10.0",
UserAgent = v10,
buildNumber = "10240",
codeName = "Threshold 1",
fullName = fullName,
Type = Type
};
case "9600":
return new Info()
{
Name = win81,
Version = "NT 6.3",
UserAgent = v81,
buildNumber = "9600",
codeName = "Blue",
fullName = fullName,
Type = Type
};
case "9200":
return new Info()
{
Name = win8,
Version = "NT 6.2",
UserAgent = v8,
buildNumber = "9200",
codeName = win8,
fullName = fullName,
Type = Type
};
case "7601":
return new Info()
{
Name = win7,
Version = "NT 6.1",
UserAgent = v7,
buildNumber = "7601",
codeName = win7,
fullName = fullName,
Type = Type
};
case "6002":
return new Info()
{
Name = winVista,
Version = "NT 6.0",
UserAgent = vVista,
buildNumber = "6002",
codeName = "Longhorn",
fullName = fullName,
Type = Type
};
case "2715":
return new Info()
{
Name = winXP,
Version = "NT 5.2",
UserAgent = vXP1,
buildNumber = "2715",
codeName = "Emerald",
fullName = fullName,
Type = Type
};
case "3790":
return new Info()
{
Name = winXP,
Version = "NT 5.2",
UserAgent = vXP1,
buildNumber = "3790",
codeName = "Anvil",
fullName = fullName,
Type = Type
};
case "2600":
return new Info()
{
Name = winXP,
Version = "NT 5.1",
UserAgent = vXP,
buildNumber = "2600",
codeName = "Symphony, Harmony, Freestyle, Whistler",
fullName = fullName,
Type = Type
};
case "3000":
return new Info()
{
Name = winMe,
Version = "4.9",
UserAgent = vMe,
buildNumber = "3000",
codeName = "Millennium",
fullName = fullName,
Type = Type
};
case "1998":
return new Info()
{
Name = win98,
Version = "4.10",
UserAgent = v98,
buildNumber = "1998",
codeName = "Memphis",
fullName = fullName,
Type = Type
};
case "2222":
return new Info()
{
Name = win98_2,
Version = "4.10",
UserAgent = v98,
buildNumber = "2222",
codeName = "Unknow",
fullName = fullName,
Type = Type
};
case "2195":
return new Info()
{
Name = win2000,
Version = "NT 5.0",
UserAgent = v2000,
buildNumber = "2195",
codeName = "Windows NT 5.0",
fullName = fullName,
Type = Type
};
default:
return new Info()
{
Name = "Unknow",
Version = "Unknow",
UserAgent = "Unknow",
buildNumber = "Unknow",
codeName = "Unknow"
};
}
}
}
关于使用这个,
var info = Windows.GetInfo();
Console.WriteLine($"Name: {info.Name}");
Console.WriteLine($"fullName: {info.fullName}");
Console.WriteLine($"UserAgent: {info.UserAgent}");
Console.WriteLine($"Type: {info.Type}");
Console.WriteLine($"codeName: {info.codeName}");
Console.WriteLine($"Version: {info.Version}");
Console.WriteLine($"buildNumber: {info.buildNumber}");
结果:
Name: Windows 10 version 21H2
fullName: Windows 10 Enterprise LTSC 2021
UserAgent: Windows NT 10
Type: x64
codeName: Vibranium
Version: 21H2
buildNumber: 19044