开发者

RegistryKey.GetSubKeyNames throws IOException

When using RegistryKey.GetSubKeyNames, an IOExeption is thrown:

"No more data is available"

Here is the relevant code:

string subKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products";
RegistryKey key = Registry.LocalMachine.OpenSubKey( subKey );
string[] keys = key.GetSubKeyNames(); // throws IOException here

Specs

  • Win7 x64
  • VS 2010 SP1
  • .NET 3.5

The exception is thrown when using a build type of "Any CPU"; when using a build type of "x86" 开发者_运维百科the code executes as expected, but reads the keys from the "Wow6432Node" instead of the SubKey path named in the defined subKey string variable above.

The question is: how can I read all the SubKeys in the subKey path defined above on a 64-bit system (not the Wow6432Node)?

Of note: When I run the same code on another 64-bit system, the code executes without error. I'm almost inclined to think I may have a corrupted registry key somewhere? If so, any ideas on how I can find the corrupt key?


Pass appropriate RegistryView to RegistryKey.OpenBaseKey().

For example:

RegistryKey tempRegKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜