Winify
/trunk/Winify/Utilities/Miscellaneous.cs |
@@ -164,6 +164,39 @@ |
} |
} |
|
/// <summary> |
/// Returns the machine GUID. |
/// </summary> |
/// <returns>the GUID of the machine</returns> |
/// <remarks>https://stackoverflow.com/questions/2333149/how-to-fast-get-hardware-id-in-c</remarks> |
public static string GetMachineGuid() |
{ |
var location = @"SOFTWARE\Microsoft\Cryptography"; |
var name = "MachineGuid"; |
|
using (var localMachineX64View = |
RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) |
{ |
using (var rk = localMachineX64View.OpenSubKey(location)) |
{ |
if (rk == null) |
{ |
throw new KeyNotFoundException( |
string.Format("Key Not Found: {0}", location)); |
} |
|
var machineGuid = rk.GetValue(name); |
if (machineGuid == null) |
{ |
throw new IndexOutOfRangeException( |
string.Format("Index Not Found: {0}", name)); |
} |
|
return machineGuid.ToString(); |
} |
} |
} |
|
#endregion |
} |
} |