コード例 #1
0
        /// <summary>
        /// Generates the Hardware ID for this machine.
        /// </summary>
        private string FindHardwareId()
        {
            //return "IJDE KQSG IJDE MMBQ GAYT ANRX IFAT AOCF GVBT IMKC MFZW KICC N5QX EZBA KNSX E2LB NQRV OOBZ GIYD ANKU G4YU";
            ManagementObjectCollection mbsList = null;
            ManagementObjectSearcher   mbs     = new ManagementObjectSearcher("Select * From Win32_processor");

            mbsList = mbs.Get();
            string id1 = "";

            foreach (ManagementObject mo in mbsList)
            {
                id1 = mo["ProcessorID"].ToString();
            }

            ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""c:""");

            dsk.Get();
            string id2 = dsk["VolumeSerialNumber"].ToString();

            ManagementObjectSearcher   mos = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
            ManagementObjectCollection moc = mos.Get();
            string id3 = "";

            foreach (ManagementObject mo in moc)
            {
                id3 = (string)mo["SerialNumber"];
            }

            ManagementObjectSearcher   bios  = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
            ManagementObjectCollection biosc = bios.Get();
            string id4 = "";

            foreach (ManagementObject mo in biosc)
            {
                id4 = (string)mo["SerialNumber"];
            }

            int idLength = 16;

            String[] ids = { id1, id2, id3, id4 };
            for (int i = 0; i < ids.Length; i++)
            {
                ids[i] = ids[i].Substring(0, Math.Min(idLength, ids[i].Length));
                ids[i] = ids[i].PadRight(idLength, '0');
            }

            //Create a UnicodeEncoder to convert between byte array and string.
            UnicodeEncoding ByteConverter = new UnicodeEncoding();

            Base32Url b32 = new Base32Url(false, false);
            String    key = b32.Encode(Encoding.Convert(Encoding.Unicode, Encoding.ASCII, ByteConverter.GetBytes(id1 + id2 + id3 + id4)));

            // Trim to multiple of 4
            key = key.Substring(0, key.Length / 4 * 4);
            //Console.WriteLine(key);
            for (int i = key.Length - 1; i >= 0; i--)
            {
                if (i % 4 == 0 && i > 0)
                {
                    key = key.Substring(0, i) + " " + key.Substring(i, key.Length - i);
                }
            }
            //Console.WriteLine(key);
            return(key);
        }
コード例 #2
0
ファイル: LicenseManager.cs プロジェクト: bartwe/Gearset
        /// <summary>
        /// Generates the Hardware ID for this machine.
        /// </summary>
        private string FindHardwareId()
        {
            //return "IJDE KQSG IJDE MMBQ GAYT ANRX IFAT AOCF GVBT IMKC MFZW KICC N5QX EZBA KNSX E2LB NQRV OOBZ GIYD ANKU G4YU";
            ManagementObjectCollection mbsList = null;
            ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_processor");
            mbsList = mbs.Get();
            string id1 = "";
            foreach (ManagementObject mo in mbsList)
                id1 = mo["ProcessorID"].ToString();

            ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""c:""");
            dsk.Get();
            string id2 = dsk["VolumeSerialNumber"].ToString();

            ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
            ManagementObjectCollection moc = mos.Get();
            string id3 = "";
            foreach (ManagementObject mo in moc)
                id3 = (string)mo["SerialNumber"];

            ManagementObjectSearcher bios = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
            ManagementObjectCollection biosc = bios.Get();
            string id4 = "";
            foreach (ManagementObject mo in biosc)
                id4 = (string)mo["SerialNumber"];

            int idLength = 16;
            String[] ids = {id1, id2, id3, id4};
            for (int i = 0; i < ids.Length; i++)
            {
                ids[i] = ids[i].Substring(0, Math.Min(idLength, ids[i].Length));
                ids[i] = ids[i].PadRight(idLength, '0');
            }

            //Create a UnicodeEncoder to convert between byte array and string.
            UnicodeEncoding ByteConverter = new UnicodeEncoding();

            Base32Url b32 = new Base32Url(false, false);
            String key = b32.Encode(Encoding.Convert(Encoding.Unicode, Encoding.ASCII, ByteConverter.GetBytes(id1 + id2 + id3 + id4)));

            // Trim to multiple of 4
            key = key.Substring(0, key.Length / 4 * 4);
            //Console.WriteLine(key);
            for (int i = key.Length - 1; i >= 0; i--)
            {
                if (i % 4 == 0 && i > 0)
                {
                    key = key.Substring(0, i) + " " + key.Substring(i, key.Length - i);
                }
            }
            //Console.WriteLine(key);
            return key;
        }