.net c# 获取运行电脑的操作系统名称,版本,位数信息
原理: 通过ManagementObjectSearcher类,查询 Win32_OperatingSystem 信息, 再通过ManagementObject遍历,
提取 Caption ,Version, OSArchitecture 信息即可
/// <summary>
/// 获取操作系统信息
/// </summary>
/// <returns></returns>
public static string GetOSInformation()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
ManagementObjectCollection moc = searcher.Get();
foreach (ManagementObject mo in moc)
{
try
{
// Windows 10 专业版,10.0.0000,64位
return ((string)mo["Caption"]).Trim() + "," + (string)mo["Version"] + "," + (string)mo["OSArchitecture"];
}
catch { }
}
return "(Win32_OperatingSystem)Unknown";
}
运行结果展示