How can I access 64-bit registry bus information from an application running in 32-bit mode on a 64-bit machine (WOW) using WMI via C #

I think the question really sums up what I'm trying to do. Here is the code I'm using. It works in all scenarios, except when my application runs in 32-bit mode on a 64-bit machine. No matter how I play arround with the __ProviderArchitecture and __RequiredArchitecture flags, I can always only access the 32-bit section of the hive (WOW6432Node)

uint LOCAL_MACHINE = 0x80000002;
string results = "";
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
options.EnablePrivileges = true;
options.Username = this.txtUser.Text;
options.Password = this.txtPassword.Text;

ManagementScope myScope = new ManagementScope("\\\\" + this.txtMachine.Text + "\\root\\default", options);
ManagementPath mypath = new ManagementPath("StdRegProv");
ManagementClass mc = new ManagementClass(myScope, mypath, null);

ManagementBaseObject inParams = mc.GetMethodParameters("EnumKey");
inParams["hDefKey"] = LOCAL_MACHINE;
inParams["sSubKeyName"] = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

ManagementNamedValueCollection objCtx = new ManagementNamedValueCollection();
objCtx.Add("__ProviderArchitecture", 64);
objCtx.Add("__RequiredArchitecture", true);


InvokeMethodOptions invokeOptions = new InvokeMethodOptions();
invokeOptions.Context = objCtx;
ManagementBaseObject outParams = mc.InvokeMethod("EnumKey", inParams, invokeOptions);

inParams = mc.GetMethodParameters("GetStringValue");
inParams["hDefKey"] = LOCAL_MACHINE;

foreach(string name in (string[])outParams["sNames"])
{
      inParams["sSubKeyName"] = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" + "\\" + name;
      inParams["sValueName"] = "DisplayName";
      outParams = mc.InvokeMethod("GetStringValue", inParams, invokeOptions);

      if (!string.IsNullOrEmpty(((string)outParams["sValue"])))
      {
          results += outParams["sValue"] + "\t";
      }
 }
+3
source share
3 answers

, , 64- . .

+1

, . 64- 32- . , , .

myScope.Options.Context.Add("__ProviderArchitecture", 64);
myScope.Options.Context.Add("__RequiredArchitecture", true);

, .net 4 (RegistryView) OpenRemoteBaseKey, . msdn

+6

KEY_WOW64_64KEY. MSDN .

Please note in particular that you are still just asking for HKLM / Software or the like. You should not try to switch to WoW6432Node redirectors, otherwise you will get stuck in a loop! More information on this topic here.

+2
source

Source: https://habr.com/ru/post/1722880/


All Articles