2

I've checked some other replies on SO but as far I can see, this is a different issue than the hits I got.

When I open RegEdit, I can see a set of keys but when I list them from my program using e.g.:

Registry.LocalMachine.OpenSubKey(@"SOFTWARE").GetSubKeyNames()

some of them are missing. I thought it might to do with the access rights so I checked .CurrentUser too. The same behavior can be experienced there. A few of the subkeys are just not listed.

What am I missing?

Martin Ender
  • 43,427
  • 11
  • 90
  • 130
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438

1 Answers1

3

Is your OS x64? If that is the case, for "LocalMachine\Software" there are two different nodes: Normal for x64 apps and Wow6432Node for x86 apps.

A sample application to demonstrate the above.

using System;
using Microsoft.Win32;

namespace ConsoleApplication1
{
  internal class Program
  {
    public static void Main()
    {
      String[] values = Registry.LocalMachine.OpenSubKey(@"SOFTWARE").GetSubKeyNames();
      foreach (String value in values)
                Console.WriteLine(value);
    }
  }
}

This is the output of the code on my machine when the console application is built in x86:

Adobe
AGEIA Technologies
Alcohol Soft
Apple Computer, Inc.
Apple Inc.
Aureal
Avira
Azureus
BazisSoft
C07ft5Y
Canon
Citrix
...

This is the output on my machine when the console application is built in x64:

7-Zip
AGEIA Technologies
Apple Computer, Inc.
Apple Inc.
ATI Technologies
Canon
Classes
Clients
...

As you see, the outputs vary a lot based on whether the application is x86 or x64.

EDIT: A similar question was asked on StackOverflow previously.

Community
  • 1
  • 1
Ganesh R.
  • 4,337
  • 3
  • 30
  • 46
  • Hmm... I might have been mistaken, then - it **might** possibly be a duplicate. Still, I'm not clear on how to handle it. I don't know what system my program will run on and I need to check for a value of a key in a certain position (e.g. `software/windows/hazaa`). The actual path, I can only check on my computer and **hope** that it's the same on the other machines. Suggestions? – Konrad Viltersten Nov 10 '12 at 20:03
  • Also, what does it mean when an application is listed in **both** the subpaths!? Is is 48-bit, then? (Average of 32 and 64 is 48, haha...) – Konrad Viltersten Nov 10 '12 at 20:07
  • @KonradViltersten How are you going to check this registry key> Via InstallShield or similar installers or C# console application? If its InstallShield (or an unmanaged app), you can access both 32 bit and 64 bit registry key using some keywords. If its C# console app and you build it in x86, it will always create and access the 32 bit registry. If its in AnyCPU it will access 32 bit in 32 bit machine and 64 bit in 64 machine. The problem will only come if the registry key is made by one application (say 32 bit) and you need to check it from AnyCPU application. – Ganesh R. Nov 11 '12 at 05:14
  • I'll be doing it from the console in C#. And I'll be targeting both 32-bit and 64-bit. I guess I'll have to compile two versions and distribute both. That was inconvenient... – Konrad Viltersten Nov 11 '12 at 10:58
  • 1
    @KonradViltersten See this if you want to only have one console application. http://stackoverflow.com/questions/8986295/weird-behaviour-when-reading-registry-in-c-sharp . Again who is creating the registry key? Is it a 32 bit app or 64 bit app? Just make your console app target the same format as the app that creates the registry key and you should be good. – Ganesh R. Nov 11 '12 at 11:10
  • Ah! >I misunderstood. I thought I needed to compile for the **OS** that the application is run in. You mean I should target the bit-ness of the application that creates the key in the registry? That's a no-brainer. It's a standard MS product, Dynamics CRM. I need to create an app that picks up some info about installation directory and stuff like that. In **that** case it shouldn't be that complicated. Thanks! – Konrad Viltersten Nov 11 '12 at 14:06
  • @KonradViltersten Does Dynamics CRM come in both 32 bit and 64 bit? If yes is one allowed to install 32 bit CRM on 64 bit machine? If the answer is No, its as easy as targetting the bitness of Dynamic CRM. Else, you have some work ahead :) – Ganesh R. Nov 11 '12 at 17:24
  • Thank you this saves me... I was trying to get some value from `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run` and not all keys were visible... – Ivandro Jao Feb 11 '17 at 17:05