如何获取计算机描述?

yon*_*236 1 c# .net-2.0

大家好,

我如何以编程方式获取计算机描述?我正在使用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());
}
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用,我得到了这个例外:

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.

Sed*_*glu 8

它在注册表值中

HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\srvcomment

访问它的最简单方法是:

using Microsoft.Win32;  

string key = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters";
string computerDescription = (string)Registry.GetValue(key, "srvcomment", null);
Run Code Online (Sandbox Code Playgroud)

  • @NicholasWilson回答你的问题:宣布它.我不是在争论你的观点,我只是说这与"理想"解决方案之间存在巨大的实用性差距.请随意添加替代方案作为代码示例的答案. (2认同)