如何为我的c#应用程序找到Microsoft Windows (Os名称)。
如'Windows 8 Pro'我的意思是来自操作系统的版本。
答案 0 :(得分:0)
您可以从注册表中获取操作系统名称,但需要查询WMI以获取体系结构和Service Pack信息:
using System.Diagnostics;
...
private string GetOperatingSystemInfo()
{
RegistryKey operatingSystemKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
string operatingSystemName = operatingSystemKey.GetValue("ProductName").ToString();
ConnectionOptions options = new ConnectionOptions();
// query any machine on the network
ManagementScope scope = new ManagementScope("\\\\machineName\\root\\cimv2", options);
scope.Connect();
// define a select query
SelectQuery query = new SelectQuery("SELECT OSArchitecture, CSDVersion FROM Win32_OperatingSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
string osArchitecture = "";
string osServicePack = "";
foreach (ManagementObject mo in searcher.Get())
{
osArchitecture = mo["OSArchitecture"].ToString();
osServicePack = mo["CSDVersion"].ToString();
}
return operatingSystemName + " " + osArchitecture + " " + osServicePack;
}
如果您需要来自WMI的更多信息,请务必查看MSDN上的Win32_OperatingSystem
课程。