大家好,如何獲取計算機說明?
我如何編程獲取計算機描述? 我正在使用C#和.NET 2.0。
我試圖Console.WriteLine(Dns.GetHostName());
,但它呼應了Full computer name
代替。
我還使用了下面的代碼:
ManagementObjectSearcher query1 = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem") ;
ManagementObjectCollection queryCollection1 = query1.Get();
foreach(ManagementObject mo in queryCollection1)
{
Console.WriteLine(mo["Description"].ToString());
}
但這似乎不工作,我得到這個異常:
Exception System.IO.FileNotFoundException was thrown in debuggee: Could not load file or assembly 'System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
您是否安裝了PowerShell? – 2012-02-09 13:31:32
你的第二種方法是正確的,但你得到的例外很奇怪。你如何添加對System.Management的引用? – 2012-02-09 13:32:00
@ AvnerShahar-Kashtan:通過使用System.Management進口它''我也將它添加到我的項目的參考中。 – yonan2236 2012-02-09 13:33:10