整容说文库 > 程序代码 > 教育资讯

如何在C#中取得主板的序列号?

来源:学生作业帮助网 编辑:整容说文库 时间:2019/12/10 18:43:48 程序代码
如何在C#中取得主板的序列号?程序代码
谢谢先。
参考下面的代码:

private void Init()
{
TreeNode myNode,myChildNode,mySubNode;
string []myClassName = new String[]{"Cooling device classes ","Input device classes","Mass storage classes ","Motherboard, controller, and port classes","Networking device classes","Power classes","Printing classes","Telephony classes","Video and monitor classes"};
string [][]myWmiClass = {
new string[]{"Win32_Fan","Win32_HeatPipe","Win32_Refrigeration","Win32_TemperatureProbe"},
new string[]{"Win32_Keyboard","Win32_PointingDevice"},
new string[]{"Win32_CDROMDrive","Win32_DiskDrive","Win32_FloppyDrive","Win32_LogicalDisk","Win32_TapeDrive"},
new string[]{"Win32_1394Controller","Win32_1394ControllerDevice","Win32_AllocatedResource","Win32_AssociatedProcessorMemory","Win32_BaseBoard","Win32_BIOS","Win32_Bus","Win32_CacheMemory","Win32_DeviceBus","Win32_DeviceMemoryAddress","Win32_DeviceSettings","Win32_DMAChannel","Win32_FloppyController","Win32_IDEController","Win32_IDEControllerDevice","Win32_InfraredDevice","Win32_IRQResource","Win32_MemoryArray","Win32_MemoryArrayLocation","Win32_MemoryDevice","Win32_MemoryDeviceArray","Win32_MemoryDeviceLocation","Win32_MotherboardDevice","Win32_OnBoardDevice","Win32_ParallelPort","Win32_PCMCIAController","Win32_PhysicalMemory","Win32_PhysicalMemoryArray","Win32_PhysicalMemoryLocation","Win32_PNPAllocatedResource","Win32_PNPDevice","Win32_PNPEntity","Win32_PortConnector","Win32_PortResource","Win32_Processor","Win32_SCSIController","Win32_SCSIControllerDevice","Win32_SerialPort","Win32_SerialPortConfiguration","Win32_SerialPortSetting","Win32_SMBIOSMemory","Win32_SoundDevice","Win32_SystemBIOS","Win32_SystemDriverPNPEntity","Win32_SystemEnclosure","Win32_SystemMemoryResource","Win32_SystemSlot","Win32_USBController","Win32_USBControllerDevice"},
new string[]{"Win32_NetworkAdapter","Win32_NetworkAdapterConfiguration","Win32_NetworkAdapterSetting"},
new string[]{"Win32_AssociatedBattery","Win32_Battery","Win32_CurrentProbe","Win32_PortableBattery","Win32_PowerManagementEvent","Win32_UninterruptiblePowerSupply","Win32_VoltageProbe"},
new string[]{"Win32_DriverForDevice","Win32_Printer","Win32_PrinterConfiguration","Win32_PrinterController","Win32_PrinterDriver","Win32_PrinterDriverDll","Win32_PrinterSetting","Win32_PrintJob","Win32_TCPIPPort"},
new string[]{"Win32_POTSModem","Win32_POTSModemToSerialPort"},
new string[]{"Win32_DesktopMonitor","Win32_DisplayConfiguration","Win32_DisplayControllerConfiguration","Win32_VideoConfiguration","Win32_VideoController","Win32_VideoSettings"}
};
sbStatus.Panels[0].Width = Width / 4;
sbStatus.Panels[1].Width = Width * 3 / 4;
tvInfoList.Width = sbStatus.Panels[0].Width;

myNode = tvInfoList.Nodes.Add("Windows Management Instrumentation(WMI)");
myNode.Tag = "";

for(int i=0;i<myClassName.Length;i++)
{
myChildNode = myNode.Nodes.Add(myClassName[i]);
myChildNode.Tag = "";
foreach(string myClass in myWmiClass[i])
{
mySubNode = myChildNode.Nodes.Add(myClass);
mySubNode.Tag = myClass;
}
}

}
private void RefreshInfo(string sInfoName)
{
if(sInfoName=="")return;

// Build a query for enumeration of Win32_BaseBoard instances
SelectQuery query = new SelectQuery(sInfoName);
ListViewItem myItem;
object myValue;

// Instantiate an object searcher with this query
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection myCollection = searcher.Get();

// lvInfoList.Enabled = false;
//No preformance raising?!
// lvInfoList.Visible = false;
lvInfoList.Items.Clear();

foreach(ManagementObject myMgmtObj in myCollection)
{
foreach(PropertyData Property in myMgmtObj.Properties)
{
myItem = lvInfoList.Items.Add(Property.Name.ToString());
myValue = Property.Value;
if(myValue==null)
{
myItem.SubItems.Add("");
}
else
{
myItem.SubItems.Add(myValue.ToString());
}
}
}
}
catch{}
}
private void MainForm_Load(object sender, System.EventArgs e)
{
Init();
}

private void tvInfoList_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
sbStatus.Panels[0].Text = "正在读取数据...";
RefreshInfo(e.Node.Tag.ToString());
sbStatus.Panels[0].Text = "就绪";
}
原来可以用WMI,我明天试试。先给分。
不行的
得不到主板的序列号,总是返回空字符串

有没有别的方法啊
gz
程序代码