/// <summary> /// 获得pc号 /// </summary> public static string GetPcsnString() { var pcsn = ""; try { var search = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS"); var mobos = search.Get(); foreach (var temp in mobos) { object serial = temp["SerialNumber"]; // ProcessorID if you use Win32_CPU pcsn = serial.ToString(); Console.WriteLine(pcsn); if ( !string.IsNullOrEmpty(pcsn) && pcsn != "To be filled by O.E.M" //没有找到 && !pcsn.Contains("O.E.M") && !pcsn.Contains("OEM") && !pcsn.Contains("Default") ) { break; } else { Console.WriteLine("默认值"); } } } catch (Exception e) { MessageBox.Show("获取过程发生异常"); //Debug.WriteLine(e); // 无法处理 } return pcsn; }