Unable to Obtain Product ID in Windows 2008 Server

advertisements

i want to use ProductId of windows machine so i have written this code but this code is unable to get the ProductId from the registry when running on windows server 2008 when i have visited registry the ProductId is there in Registry

string[] names = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValueNames();
foreach (string s in names)
{
  listBox1.Items.Add(s);
}


I found out the reason this happens. It's because your program is 32-bit and your system is 64-bit. 32-bit programs access the 32-bit portion of the registry, and this key is not present in the 32-bit portion, which is located in:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion

Compile your program in 64-bit and it's will work.