示例#1
0
        public static string GetHDSerialNo()
        {
            string stRetValue = Constants.ERROR;

            try
            {
                OSVersion osVersion = OSInformation.getOSVersion();
                switch (osVersion)
                {
                case OSVersion.Windows95:
                case OSVersion.WindowsMe:
                case OSVersion.Windows98:
                case OSVersion.Windows98SecondEdition:
                case OSVersion.WindowsNT351:
                case OSVersion.WindowsNT4:
                case OSVersion.Windows2000:
                case OSVersion.WindowsXP:
                    const string RegCode  = "NW5KF-49VU2-CW1VD-EH32P-UFEL2";
                    DiskInfo     diskInfo = new DiskInfo();

                    HDiskInfo.GetIdeDiskInfo(0, ref diskInfo, RegCode);
                    stRetValue = diskInfo.pSerialNumber;
                    break;

                case OSVersion.WindowsVista:
                case OSVersion.Windows7:
                    ManagementClass            mc  = new ManagementClass("Win32_PhysicalMedia");
                    ManagementObjectCollection moc = mc.GetInstances();
                    foreach (ManagementObject mo in moc)
                    {
                        if (mo.ToString().ToUpper().IndexOf("PHYSICALDRIVE0") != -1)
                        {
                            stRetValue = mo["SerialNumber"].ToString().Trim();
                            mo.Dispose();
                            break;
                        }
                        mo.Dispose();
                    }
                    break;

                case OSVersion.Unknown:
                    break;
                }

                return(stRetValue);
            }
            catch (Exception ex)
            {
                return(stRetValue + ":" + ex.Message);
            }
        }
示例#2
0
 public static extern int GetIdeDiskInfo(int DriveNo, ref DiskInfo tt, string sRegNumber);
示例#3
0
		public static extern int GetIdeDiskInfo(int DriveNo,ref DiskInfo tt, string sRegNumber);
示例#4
0
        public static string GetHDSerialNo()
        {
            string stRetValue = Constants.ERROR;
            try
            {
                OSVersion osVersion = OSInformation.getOSVersion();
                switch (osVersion)
                {
                    case OSVersion.Windows95:
                    case OSVersion.WindowsMe:
                    case OSVersion.Windows98:
                    case OSVersion.Windows98SecondEdition:
                    case OSVersion.WindowsNT351:
                    case OSVersion.WindowsNT4:
                    case OSVersion.Windows2000:
                    case OSVersion.WindowsXP:
                        const string RegCode = "NW5KF-49VU2-CW1VD-EH32P-UFEL2";
                        DiskInfo diskInfo = new DiskInfo();

                        HDiskInfo.GetIdeDiskInfo(0, ref diskInfo, RegCode);
                        stRetValue = diskInfo.pSerialNumber;
                        break;
                    case OSVersion.WindowsVista:
                    case OSVersion.Windows7:
                        ManagementClass mc = new ManagementClass("Win32_PhysicalMedia");
                        ManagementObjectCollection moc = mc.GetInstances();
                        foreach (ManagementObject mo in moc)
                        {
                            if (mo.ToString().ToUpper().IndexOf("PHYSICALDRIVE0") != -1)
                            {
                                stRetValue = mo["SerialNumber"].ToString().Trim();
                                mo.Dispose();
                                break;
                            }
                            mo.Dispose();
                        }
                        break;
                    case OSVersion.Unknown:
                        break;
                }

                return stRetValue;
            }
            catch (Exception ex)
            {
                return stRetValue + ":" + ex.Message;
            }
        }