实现效果:
知识运用:
WMI管理类中的ManagementObjectSearcher类生成一个设备管理信息对象
使用ManagementObject类遍历设备管理器对象
实现代码:
private void Form1_Load(object sender, EventArgs e) { ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * from Win32_physicalMedia"); string strHardDiskID = null; foreach (ManagementObject mo in searcher.Get()) { strHardDiskID=mo["SerialNumber"].ToString(); } label1.Text = "磁盘序列号:" + strHardDiskID; }