private static string GetSystemUuid()
 {
     try
     {
         // read the UUID of the system
         using (var searcher = new ManagementObjectSearcher("SELECT UUID FROM Win32_ComputerSystemProduct"))
         {
             using (var results = new ManagementObjectSearcherResults(searcher))
             {
                 foreach (var system in results)
                 {
                     var uuid = system.GetString("UUID");
                     if (uuid != null)
                     {
                         uuid = uuid.Trim();
                     }
                     if (!string.IsNullOrEmpty(uuid))
                     {
                         return(uuid);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Platform.Log(LogLevel.Debug, ex, "Failed to retrieve system UUID.");
     }
     return(string.Empty);
 }
        private static string GetDiskSignature()
        {
            try
            {
                // identify the disk drives sorted by hardware order
                var diskDrives = new SortedList <uint, uint>();
                using (var searcher = new ManagementObjectSearcher("SELECT Index, Signature FROM Win32_DiskDrive"))
                {
                    using (var results = new ManagementObjectSearcherResults(searcher))
                    {
                        foreach (var diskDrive in results)
                        {
                            var index     = diskDrive.GetUInt32("Index");
                            var signature = diskDrive.GetUInt32("Signature");
                            if (index.HasValue && signature.HasValue)
                            {
                                diskDrives.Add(index.Value, signature.Value);
                            }
                        }
                    }
                }

                // use the signature of the first physical disk drive
                foreach (var diskDriveId in diskDrives)
                {
                    return(diskDriveId.Value.ToString("X8", CultureInfo.InvariantCulture));
                }
            }
            catch (Exception ex)
            {
                Platform.Log(LogLevel.Debug, ex, "Failed to retrieve disk drive signature.");
            }
            return(string.Empty);
        }
 private static string GetMotherboardSerial()
 {
     try
     {
         // read the s/n of the motherboard
         using (var searcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BaseBoard"))
         {
             using (var results = new ManagementObjectSearcherResults(searcher))
             {
                 foreach (var motherboard in results)
                 {
                     var serialNumber = motherboard.GetString("SerialNumber");
                     if (serialNumber != null)
                     {
                         serialNumber = serialNumber.Trim();
                     }
                     if (!string.IsNullOrEmpty(serialNumber))
                     {
                         return(serialNumber);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Platform.Log(LogLevel.Debug, ex, "Failed to retrieve baseboard serial number.");
     }
     return(string.Empty);
 }
Example #4
0
 private static string GetSystemVolumeSerial()
 {
     try
     {
         // read the volume serial of the system drive
         var systemDrive = (Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System)) ?? "C:").TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).ToUpperInvariant();
         using (var searcher = new ManagementObjectSearcher(string.Format("SELECT VolumeSerialNumber FROM Win32_LogicalDisk WHERE DeviceID='{0}'", WqlEscape(systemDrive))))
             using (var results = new ManagementObjectSearcherResults(searcher))
             {
                 foreach (var logicalDisk in results)
                 {
                     var volumeSerial = logicalDisk.GetString("VolumeSerialNumber");
                     if (volumeSerial != null)
                     {
                         volumeSerial = volumeSerial.Trim();
                     }
                     if (!string.IsNullOrEmpty(volumeSerial))
                     {
                         return(volumeSerial);
                     }
                 }
             }
     }
     catch (Exception ex)
     {
         Platform.Log(LogLevel.Debug, ex, "Failed to retrieve system volume serial.");
     }
     return(string.Empty);
 }
Example #5
0
 private static string GetBiosSerial()
 {
     try
     {
         // read the s/n of BIOS
         using (var searcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BIOS"))
             using (var results = new ManagementObjectSearcherResults(searcher))
             {
                 foreach (var bios in results)
                 {
                     var serialNumber = bios.GetString("SerialNumber");
                     if (serialNumber != null)
                     {
                         serialNumber = serialNumber.Trim();
                     }
                     if (!string.IsNullOrEmpty(serialNumber))
                     {
                         return(serialNumber);
                     }
                 }
             }
     }
     catch (Exception ex)
     {
         Platform.Log(LogLevel.Debug, ex, "Failed to retrieve BIOS serial number.");
     }
     return(string.Empty);
 }
        private static string GetProcessorId()
        {
            try
            {
                // read the CPUID of the first processor
                using (var searcher = new ManagementObjectSearcher("SELECT ProcessorId FROM Win32_Processor"))
                {
                    using (var results = new ManagementObjectSearcherResults(searcher))
                    {
                        foreach (var processor in results)
                        {
                            var processorId = processor.GetString("ProcessorId");
                            if (processorId != null)
                            {
                                processorId = processorId.Trim();
                            }
                            if (!string.IsNullOrEmpty(processorId))
                            {
                                return(processorId);
                            }
                        }
                    }
                }

                // if the processor doesn't support the CPUID opcode, concatenate some immutable characteristics of the processor
                using (var searcher = new ManagementObjectSearcher("SELECT Manufacturer, AddressWidth, Architecture, Family, Level, Revision FROM Win32_Processor"))
                {
                    using (var results = new ManagementObjectSearcherResults(searcher))
                    {
                        foreach (var processor in results)
                        {
                            var manufacturer = processor.GetString("Manufacturer");
                            var addressWidth = processor.GetUInt16("AddressWidth");
                            var architecture = processor.GetUInt16("Architecture");
                            var family       = processor.GetUInt16("Family");
                            var level        = processor.GetUInt16("Level");
                            var revision     = processor.GetUInt16("Revision");
                            return(string.Format(CultureInfo.InvariantCulture, "CPU-{0}-{1}-{2:X2}-{3:X2}-{4}-{5:X4}", manufacturer, addressWidth, architecture, family, level, revision));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Platform.Log(LogLevel.Debug, ex, "Failed to retrieve processor ID.");
            }
            return(string.Empty);
        }