title: How to use the "__ProviderArchitecture" flag of IWbemContext in c?
body: <p>I've been trying to follow the following <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa393067%28v=vs.85%29.aspx" rel="nofollow">MSDN tutorial</a> to query the 64 bit registry provider from a 32 bit application.</p>
  
  <p>Sadly, the examples are all written in VB, and I'm stuck with something.</p>
  
  <p>For C++ developers, the article mentions that...</p>
  
  <blockquote>
    <p>C++ applications can use the IWbemContext interface with IWbemServices::ExecMethod to communicate the use of a nondefault provider to WMI.</p>
  </blockquote>
  
  <p>...although, when you look at the sample VB code, the context object is also used in the <code>ConnectServer</code> method:</p>
  
  <pre><code>Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
  objCtx.Add "__ProviderArchitecture", 32
  Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
  Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
  Set objStdRegProv = objServices.Get("StdRegProv") 
  </code></pre>
  
  <p>I've tried reproducing this in VC++:</p>
  
  <pre><code>HRESULT res;
  CComPtr&lt;IWbemContext&gt; ctx;
  if (!create_registry_redirection_context_(hive, ctx)) {
      return false;
  }
  
  res = locator_-&gt;ConnectServer(CComBSTR(namespace_.c_str()),     // Namespace to use
                                0,                                // Current security context (username)
                                0,                                // Current security context (password)
                                0,                                // Use current locale
                                WBEM_FLAG_CONNECT_USE_MAX_WAIT,   // Return if connexion is unsuccessful after 2 minutes
                                0,                                // Name of the domain  of the user to authenticate
                                ctx,                              // Optional context
                                &amp;service_);                       // Fill this pointer
  </code></pre>
  
  <p>The <code>create_registry_redirection_context_</code> method uses <code>CoCreateInstance</code> to instantiate my context, and I use the following lines to set the architecture:</p>
  
  <pre><code>CComVariant value_arch(64, VT_I4);
  ctx-&gt;SetValue(L"__ProviderArchitecture", 0, &amp;value_arch);
  </code></pre>
  
  <p>Now the problem is, the <code>ConnectServer</code> method returns an error (0x80041008 - WMI Invalid Parameter). If I comment out the <code>ctx-&gt;SetValue(L"__ProviderArchitecture", 0, &amp;value_arch);</code> line, everything works properly, but of course, I end up querying the 32 bit registry provider.</p>
  
  <p>I've also tried not setting any context during the <code>ConnectServer</code> call, but only during the <code>ExecMethod</code> call (as specified in the MSDN article), but although I don't get any error, I'm still querying the 32 bit provider, and not seeing my 64bit registry keys.</p>
  
  <p>What am I doing wrong?
  Thanks in advance for your time.</p>