Reputation: 458
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);
}
Upvotes: 0
Views: 756
Reputation: 11
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.
Upvotes: 1
Reputation: 499002
Make sure the account this code is running under has permissions to read from the registry (or at least that location in the registry).
Upvotes: 0