title: Searching x32 registry keys from a x64 program
body: <p>I'm writing a C# application that is for x64 and my problem is that <strong>i'm searching the registry for some keys that contain certain keywords</strong> and and i am only able to search the registry of x64 applications because of registry redirection.
  <br/>
  I manged to find some code on the net but i don't really know what to do with it because from what i understand it only works if i know the exact key name while i'm searching for patterns or keywords.
          [DllImport("advapi32.dll", EntryPoint = "RegOpenKeyEx")]
          public static extern int RegOpenKeyEx_DllImport(
              UIntPtr hKey,
              string subKey,
              uint options,
              int sam,
              out IntPtr phkResult);</p>
  
  <pre><code>    [DllImport("advapi32.dll", EntryPoint = "RegQueryValueEx")]
      static extern int RegQueryValueEx_DllImport(
          IntPtr hKey,
          string lpValueName,
          int lpReserved,
          out uint lpType,
          System.Text.StringBuilder lpData,
          ref uint lpcbData);
  
  public string GetKeyValue(string strSubKey, string strKey)
      {
  
          UIntPtr HKEY_LOCAL_MACHINE = (UIntPtr)0x80000002;
          const int KEY_WOW64_32KEY = 0x0200;
          const int KEY_QUERY_VALUE = 0x1;
  
          IntPtr hKeyVal;
          uint lpType;
          uint lpcbData = 0;
          System.Text.StringBuilder pvData = new System.Text.StringBuilder(1024);
          int valueRet;
  
  
  
          string returnPath = String.Empty;
          unchecked
          {
              try
              {   //Open the required key path
                  valueRet = RegOpenKeyEx_DllImport(HKEY_LOCAL_MACHINE, strSubKey, 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, out hKeyVal);
  
                  //Retreive the key value
                  valueRet = RegQueryValueEx_DllImport(hKeyVal, strKey, 0, out lpType, pvData, ref lpcbData);
  
                  valueRet = RegQueryValueEx_DllImport(hKeyVal, strKey, 0, out lpType, pvData, ref lpcbData);
  
                  returnPath = pvData.ToString();
              }
              catch (Exception e)
              {
                  throw (e);
              }
          }
          return returnPath;
      }
  </code></pre>