使用C#获取系统信息

5

如何获取计算机的系统信息。

  1. 系统制造商:

  2. 系统型号:

  3. Bios版本:


2
读取 注册表:例如 HKLM\Hardware\System\Bios\BIOSVersion - Dmitry Bychenko
5
这个问题不应该被“关闭为过于宽泛”。它是一个非常具体的问题,下面已经提供了非常具体的答案。 - Joe Gayetty
3个回答

14
你可以使用以下方法获取制造商名称,需要添加对 System.Management 的引用。
 System.Management.SelectQuery query = new System.Management.SelectQuery(@"Select * from Win32_ComputerSystem");

 //initialize the searcher with the query it is supposed to execute
 using (System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query))
 {
     //execute the query
     foreach (System.Management.ManagementObject process in searcher.Get())
     {
         //print system info
         process.Get();
         Console.WriteLine("/*********Operating System Information ***************/");
         Console.WriteLine("{0}{1}", "System Manufacturer:", process["Manufacturer"]);
         Console.WriteLine("{0}{1}", " System Model:", process["Model"]);


     }
 }

 System.Management.ManagementObjectSearcher searcher1 = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
 System.Management.ManagementObjectCollection collection = searcher1.Get();


foreach (ManagementObject obj in collection)
{
    if ( ((string[])obj["BIOSVersion"]).Length > 1)
        Console.WriteLine("BIOS VERSION: " + ((string[])obj["BIOSVersion"])[0] + " - " + ((string[])obj["BIOSVersion"])[1]);
    else
        Console.WriteLine("BIOS VERSION: " + ((string[])obj["BIOSVersion"])[0]);
}

来源


它不会带来他所需要的一切! - Pedro Augusto Freitas de Souza
1
@PedroAugusto,因为我总是更喜欢发布代码而不是链接到其他地方,所以花了一些时间来发布完整的代码。现在我已经更新了它,请您尝试一下,如果我漏掉了 OP 想要的任何内容,请告诉我! - Arindam Nayak
好的朋友,现在我认为答案符合所有要求! - Pedro Augusto Freitas de Souza
@mammoth,代码已更新,现在应该可以工作了。之前我不确定你需要什么。 - Arindam Nayak
感谢Arindam制造商和型号完美运作。在BIOS信息上遇到了问题,显示“索引超出了数组范围”。 - mammoth
显示剩余3条评论

2

0

3
该链接已失效。 - Rufus L

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接