Advertisement
crackanddie

get_unique_id

May 19th, 2022
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. public static string GetDeviceUniqueIdentifier()
  2.         {
  3.             string ret = string.Empty;
  4.  
  5.             string concatStr = string.Empty;
  6.             try
  7.             {
  8.                 ManagementObjectSearcher searcherBb = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
  9.                 foreach (var obj in searcherBb.Get())
  10.                 {
  11.                     concatStr += (string)obj.Properties["SerialNumber"].Value ?? string.Empty;
  12.                 }
  13.  
  14.                 ManagementObjectSearcher searcherBios = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
  15.                 foreach (var obj in searcherBios.Get())
  16.                 {
  17.                     concatStr += (string)obj.Properties["SerialNumber"].Value ?? string.Empty;
  18.                 }
  19.  
  20.                 ManagementObjectSearcher searcherOs = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
  21.                 foreach (var obj in searcherOs.Get())
  22.                 {
  23.                     concatStr += (string)obj.Properties["SerialNumber"].Value ?? string.Empty;
  24.                 }
  25.  
  26.                 var sha1 = SHA1.Create();
  27.                 ret = string.Join("", sha1.ComputeHash(Encoding.UTF8.GetBytes(concatStr)).Select(b => b.ToString("x2")));
  28.             }
  29.             catch (Exception e)
  30.             {
  31.                 Console.WriteLine(e.ToString());
  32.             }
  33.  
  34.             return ret;
  35.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement