c# 获取 bios 序列号

时间:2022-10-22 21:33:04
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Diagnostics; namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Debug.Print(getBiosSN()); } public static string getBiosSN()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_BIOS");
ManagementObjectCollection objects = searcher.Get();
foreach (ManagementObject obj in objects)
{
try
{
if (obj.GetPropertyValue("SerialNumber") != null)
{
return obj["SerialNumber"].ToString();
}
}
catch (Exception)
{
}
} return string.Empty;
}
}
}