示例#1
0
        public string GetDeviceID()
        {
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.System.Profile.HardwareIdentification"))
            {
                Windows.System.Profile.HardwareToken token = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
                IBuffer    hardwareId = token.Id;
                DataReader hdIdReader = DataReader.FromBuffer(hardwareId);

                byte[] bytes = new byte[hardwareId.Length];
                hdIdReader.ReadBytes(bytes);

                return(BitConverter.ToString(bytes));
            }
            return("");
        }
示例#2
0
        }   // end of MoveAllFiles()

        /// <summary>
        /// Generates a unique ID for the current machine.  Used to make autosave files unique.
        /// Original version used Hhashed MAC Address but that's not available in WinRT.
        /// </summary>
        /// <returns></returns>
        private static string GetHashedMachineID()
        {
            string result = String.Empty;

            try
            {
                // Generate a unique string based on several hardware identifiers.  Probably overkill.
                Windows.System.Profile.HardwareToken hardwareToken = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
                using (DataReader dataReader = DataReader.FromBuffer(hardwareToken.Id))
                {
                    int offset = 0;
                    while (offset < hardwareToken.Id.Length)
                    {
                        byte[] hardwareEntry = new byte[4];
                        dataReader.ReadBytes(hardwareEntry);

                        // CPU ID of the processor || Size of the memory || Serial number of the disk device || BIOS
                        if ((hardwareEntry[0] == 1 || hardwareEntry[0] == 2 || hardwareEntry[0] == 3 || hardwareEntry[0] == 9) && hardwareEntry[1] == 0)
                        {
                            if (!string.IsNullOrEmpty(result))
                            {
                                result += "|";
                            }
                            result += string.Format("{0}.{1}", hardwareEntry[2], hardwareEntry[3]);
                        }
                        offset += 4;
                    }
                }
            }
            catch (Exception e)
            {
                if (e != null)
                {
                }
            }

            result = result.GetHashCode().ToString();

            return(result);
        }   // end of GetHashedMachineID()