问题
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.
回答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
来源:https://stackoverflow.com/questions/58649651/searching-registry-keys-giving-different-outputs-in-net-core-and-net-framwork