I have recently moved to a W7 64bit machine with VS 2010.
My project is set to run on Any CPU
. When I change this to be targeted at x86
I noticed s
This code will get the id for all kinds of os architectures and program architectures. Could be written shorter but I like the readability
static string GetProductId()
{
RegistryKey localMachine = null;
if (Environment.Is64BitOperatingSystem)
{
localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
}
else
{
localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
}
RegistryKey windowsNTKey = localMachine.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion");
return windowsNTKey.GetValue("ProductId").ToString();
}