確定安裝的Windows Edition System.Environment.OSVersion似乎並未指明安裝了哪個版本的Windows 2003(Standard,Enterprise,DataCenter)。如何使用.net
有什麼方法可以使用託管代碼訪問這些信息嗎?
我知道我可以使用P/Invoke調用GetVersionEx並檢查OSVERSIONINFOEX.wSuiteMask以獲取此信息,但我正在尋找更簡單的解決方案。
更新
使用WMI看起來像的路要走,雖然Win32_OperatingSystem的OSProductSuite財產看起來比Name屬性更可靠。以下是示例代碼:
ManagementScope scope = new ManagementScope();
ObjectQuery query = new ObjectQuery("SELECT name, csdversion, description, OperatingSystemSKU, OSProductSuite FROM Win32_OperatingSystem");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
{
using (ManagementObjectCollection resultCollection = searcher.Get())
{
foreach (ManagementObject result in resultCollection)
{
foreach (PropertyData propertyData in result.Properties)
{
Debug.WriteLine(
propertyData.Name + ": " +
((propertyData.Value == null) ? "" : propertyData.Value.ToString())
);
}
}
}
}
該pinvoke方式似乎很簡單。 – leppie 2009-10-28 11:38:56