I am trying to fetch
string key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography";
string r = (string)Registry.GetValue(key, "MachineGuid", (object)"default");
As other people have already pointed out, you are not supposed to get that value directly from the registry (which is probably why it doesn't work reliably among different versions of Windows).
A little searching led me to the
Win32_OperatingSystem WMI class. Using this class, you can actually get the Windows serial number. It took me some searching and experimenting to get it right, but this is how to use it in C#.
Make sure you have the
System.Management.dll reference in your project:
using System.Management; ... ManagementObject os = new ManagementObject("Win32_OperatingSystem=@"); string serial = (string)os["SerialNumber"];
 operator, you can get any property in the class.