C#获取硬盘序列号

            //创建ManagementObjectSearcher对象
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
            String strHardDiskID = null;//存储磁盘序列号
            //调用ManagementObjectSearcher类的Get方法取得硬盘序列号
            foreach (ManagementObject mo in searcher.Get())
            {
                strHardDiskID = mo["SerialNumber"].ToString().Trim();//记录获得的磁盘序列号
                break;
            }
            label1.Text = "硬盘序列号: "+strHardDiskID;//显示硬盘序列号

 

posted @ 2018-05-02 14:16  enych  阅读(8750)  评论(1编辑  收藏  举报