我用wmi获取pnpdevieID是IDE\DISKST3160215AS_____________________________4.AAB___\5&B140DE0&0&0.0.0 
而我用Dos获得的硬盘序列号是46EB-C82F
请问这是为什么呀,哪个是正确的,哪个是唯一的;若不正确,怎样获得正确的序列号?
请各位大侠出手相助啊!!!

解决方案 »

  1.   


    try
                {
                    ManagementClass mc = new ManagementClass("Win32_DiskDrive");
                    ManagementObjectCollection moc = mc.GetInstances();                foreach (ManagementObject mo in moc)
                            foreach (PropertyData property in mo.Properties)
                            {
                                Console.Write(property.Name + " --- ");
                                try
                                {
                                    Console.WriteLine(mo.Properties[property.Name].Value.ToString());
                                }
                                catch
                                {
                                    Console.WriteLine();
                                }
                            }
                    }执行上面这段代码,系统中所有硬盘中所有的东西都读出来了.要哪个取哪个.
      

  2.   

    我用的就是这段代码,得到的是IDE\DISKST3160215AS_____________________________4.AAB___\5&B140DE0&0&0.0.0
    好恐怖的一个序列号呀
      

  3.   

    /// <summary>
            /// 硬盘序列号。
            /// </summary>
            public static string HardDiskID
            {
                get
                {
                    if(String.IsNullOrEmpty(_hardDiskID))
                    {
                        try
                        {
                            string filename = System.IO.Path.Combine(FileUtil.AppDir, "harddisk.txt");
                            System.IO.StreamWriter writer = new System.IO.StreamWriter(filename, false);
                            ManagementClass cimobject = new ManagementClass("Win32_DiskDrive");
                            ManagementObjectCollection moc = cimobject.GetInstances();
                            foreach (ManagementObject mo in moc)
                            {
                                foreach (PropertyData property in mo.Properties)
                                {
                                    writer.WriteLine("{0} = {1};", property.Name, property.Value);
    #if DEBUG
                                    Console.WriteLine("{0} = {1};", property.Name, property.Value);
    #endif
                                }
                                _hardDiskID = (string)mo.Properties["SerialNumber"].Value;
                                if (!string.IsNullOrEmpty(_hardDiskID) && !IsException)
                                {
                                    writer.Close();
                                    System.IO.File.Delete(filename);
                                    break;
                                }
                                mo.Dispose();
                            }
                            writer.Close();
                            moc.Dispose();
                        }
                        catch //(Exception ex)
                        {
                        }
                    }
                    return _hardDiskID;
                }
            }我用这个代码是好的呀,你是不是参数写错了?你用的是哪个参数读到的?
      

  4.   

    是否有办法得到和HDTune一样的序列号