1

While searching for a particular registry key under Local machine SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall using C#, the >net framework application is giving different result than in .Net core App

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false);

Console.WriteLine(key.GetSubKeyNames().Length);
foreach (String keyName in key.GetSubKeyNames())
{

    RegistryKey subkey = key.OpenSubKey(keyName);
    string displayName = subkey.GetValue("DisplayName") as string;
    if (displayName == null)
    {
        Console.WriteLine("NULL");
        continue;
    }
    Console.WriteLine(displayName);
    if (displayName.Contains("MyApp") == true)
    {
        Console.WriteLine("Found");
        return;
    }
}

.Net framework giving out 863 names and .net core giving 247 different set of outcome.

stuartd
  • 70,509
  • 14
  • 132
  • 163
  • Are both your .NET framework and .NET applications running under the same user and have the same permissions? – Claudiu Guiman Oct 31 '19 at 19:04
  • I have opened both the projects in the same solution in VS under Admin rights. – abhiroop mukherjee Oct 31 '19 at 19:09
  • Are both console applications? Try and find a key that's only visible to one and see if it has any special ACL – Claudiu Guiman Oct 31 '19 at 19:11
  • Yes. One is .Net core 2.2 and the other is .Net Framework 4.6.1 – abhiroop mukherjee Oct 31 '19 at 19:12
  • I checked the permissions in registry. Looks both are having same permissions. Although, i found that the list for the .Net framework is actually coming from SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\ while the list for .Net core is correctly coming from SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\. Let me know if this info helps. – abhiroop mukherjee Oct 31 '19 at 19:35

1 Answers1

1

I suspect the .NET Framework app is 32 bit program and the .NET Core app runs under the 64 bit runtime.

If you want to enumerate the WOW64 registry in the .NET Core app you can follow the instructions here: How to open a WOW64 registry key from a 64-bit .NET application

Claudiu Guiman
  • 837
  • 5
  • 18
  • 2
    Yes. I tried the same approach and it worked. I added the following line to access 64bit registery keys. RegistryKey key1 = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64); RegistryKey key = key1.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true); Thanks for the help. – abhiroop mukherjee Oct 31 '19 at 19:50