Advertisement
Dev

GetMachineGuid C#

Dev
Jul 18th, 2017
39,275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #UDT
  2. #UltimateDevTeam
  3.  
  4. public static string GetMachineGuid()
  5. {
  6. string location = @"SOFTWARE\Microsoft\Cryptography";
  7. string name = "MachineGuid";
  8.  
  9. using (RegistryKey localMachineX64View = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
  10. {
  11. using (RegistryKey rk = localMachineX64View.OpenSubKey(location))
  12. {
  13. if (rk == null)
  14. throw new KeyNotFoundException(string.Format("Key Not Found: {0}", location));
  15.  
  16. object machineGuid = rk.GetValue(name);
  17. if (machineGuid == null)
  18. throw new IndexOutOfRangeException(string.Format("Index Not Found: {0}", name));
  19.  
  20. return machineGuid.ToString();
  21. }
  22. }
  23. }
  24.  
  25. #UDT
  26. #UltimateDevTeam
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement