Boost C++ Libraries: Ticket #5552: get_wmi_class_attribute hangs on win2003 https://svn.boost.org/trac10/ticket/5552 <p> I found this problem while I was using shared_memory. Function hangs on call to pIWbemLocator-&gt;<a class="missing wiki">ConnectServer</a>. </p> <p> The solution to this issue is changing <a class="missing wiki">CoInitialize</a>(0) at the beginning of function to <a class="missing wiki">CoInitializeEx</a>(0, COINIT_MULTITHREADED). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5552 Trac 1.4.3 Tsukasa Kusakabe <kusakabe@…> Tue, 06 Sep 2011 04:20:53 GMT <link>https://svn.boost.org/trac10/ticket/5552#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5552#comment:1</guid> <description> <p> This problem is irrelevant to "<a class="missing wiki">CoInitializeEx</a>(0, COINIT_MULTITHREADED)". (There is a possibility of operating by chance.) </p> <p> The problem is dependence on "<a class="missing wiki">CoInitializeSecurity</a>" that cannot be used two times or more. </p> <p> Therefore, the problem that "<a class="missing wiki">ExecQuery</a>" fails when "<a class="missing wiki">CoInitializeSecurity</a>" has already been used happens. (Please refer to the following reproduction code.) </p> <p> Solving it by using both "<a class="missing wiki">CoInitializeSecurity</a>" and "<a class="missing wiki">CoSetProxyBlanket</a>" is correct. </p> <h3 class="section" id="Reproductioncode">Reproduction code</h3> <div class="wiki-code"><div class="code"><pre> <span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;Windows.h&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/interprocess/detail/win32_api.hpp&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="o">::</span><span class="n">CoInitialize</span><span class="p">(</span><span class="nb">NULL</span><span class="p">);</span> <span class="o">::</span><span class="n">CoInitializeSecurity</span><span class="p">(</span> <span class="nb">NULL</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="n">RPC_C_AUTHN_LEVEL_CONNECT</span><span class="p">,</span> <span class="n">RPC_C_IMP_LEVEL_IDENTIFY</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="n">EOAC_NONE</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">str</span><span class="p">;</span> <span class="k">const</span> <span class="kt">bool</span> <span class="n">result</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">interprocess</span><span class="o">::</span><span class="n">winapi</span><span class="o">::</span><span class="n">get_last_bootup_time</span><span class="p">(</span><span class="n">str</span><span class="p">);</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span> <span class="k">const</span> <span class="n">boolean</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s">&quot;true&quot;</span><span class="p">,</span> <span class="s">&quot;false&quot;</span><span class="p">};</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">boolean</span><span class="p">[</span><span class="n">result</span> <span class="o">?</span> <span class="mi">0</span> <span class="o">:</span> <span class="mi">1</span><span class="p">]</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;:&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">str</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="c1">// =&gt; &quot;false:Select LastBootUpTime from Win32_OperatingSystem&quot;</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><h3 class="section" id="Patch">Patch</h3> <div class="wiki-code"> <div class="diff"> <ul class="entries"> <li class="entry"> <h2> <a>boost/interprocess/detail/win32_api.hpp</a> </h2> <table class="trac-diff inline" cellspacing="0"> <colgroup> <col class="lineno"/><col class="lineno"/><col class="content"/> </colgroup> <thead> <tr> <th title="File boost/interprocess/detail/win32_api.hpp (revision 74236)"> </th> <th title="File boost/interprocess/detail/win32_api.hpp (working copy)"> </th> <td> <em></em> &nbsp; </td> </tr> </thead> <tbody class="unmod"> <tr> <th>164</th><th>164</th><td class="l"><span>static unsigned long key_query_value&nbsp; &nbsp; = 0x0001;</span></td> </tr> <tr> <th>165</th><th>165</th><td class="l"><span></span></td> </tr> <tr> <th>166</th><th>166</th><td class="l"><span>//COM API</span></td> </tr> </tbody> <tbody class="add"> <tr class="first"> <th>&nbsp;</th><th>167</th><td class="r"><ins>const long RPC_C_AUTHN_DEFAULT_IG = 0xffffffffL;</ins></td> </tr> <tr class="last"> <th>&nbsp;</th><th>168</th><td class="r"><ins>const long RPC_C_AUTHZ_DEFAULT_IG = 0xffffffffL;</ins></td> </tr> </tbody> <tbody class="unmod"> <tr> <th>167</th><th>169</th><td class="l"><span>const long RPC_C_AUTHN_LEVEL_PKT_IG = 4;</span></td> </tr> <tr> <th>168</th><th>170</th><td class="l"><span>const long RPC_C_IMP_LEVEL_IMPERSONATE_IG = 3;</span></td> </tr> <tr> <th>169</th><th>171</th><td class="l"><span>const long EOAC_NONE_IG = 0;</span></td> </tr> </tbody> <tbody class="skipped"> <tr> <th><a href="#L865">&hellip;</a></th> <th><a href="#L867">&hellip;</a></th> <td> <em></em> &nbsp; </td> </tr> </tbody> <tbody class="unmod"> <tr> <th>865</th><th>867</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *pAuthList,</span></td> </tr> <tr> <th>866</th><th>868</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unsigned long&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwCapabilities,</span></td> </tr> <tr> <th>867</th><th>869</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *pReserved3 );</span></td> </tr> </tbody> <tbody class="add"> <tr class="first"> <th>&nbsp;</th><th>870</th><td class="r"><ins>extern "C" __declspec(dllimport) long __stdcall CoSetProxyBlanket(</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>871</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IUnknown_IG *pProxy,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>872</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unsigned long dwAuthnSvc,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>873</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unsigned long dwAuthzSvc,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>874</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wchar_t *pServerPrincName,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>875</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unsigned long dwAuthnLevel,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>876</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unsigned long dwImpLevel,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>877</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void *pAuthInfo,</ins></td> </tr> <tr class="last"> <th>&nbsp;</th><th>878</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unsigned long dwCapabilities);</ins></td> </tr> </tbody> <tbody class="unmod"> <tr> <th>868</th><th>879</th><td class="l"><span></span></td> </tr> <tr> <th>869</th><th>880</th><td class="l"><span>extern "C" __declspec(dllimport) long __stdcall VariantClear(wchar_variant * pvarg);</span></td> </tr> <tr> <th>870</th><th>881</th><td class="l"><span>extern "C" __declspec(dllimport) long __stdcall CoCreateInstance(const GUID_IG &amp; rclsid, IUnknown_IG *pUnkOuter,</span></td> </tr> </tbody> <tbody class="skipped"> <tr> <th><a href="#L1648">&hellip;</a></th> <th><a href="#L1659">&hellip;</a></th> <td> <em></em> &nbsp; </td> </tr> </tbody> <tbody class="unmod"> <tr> <th>1648</th><th>1659</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;</span></td> </tr> <tr> <th>1649</th><th>1660</th><td class="l"><span>&nbsp; &nbsp; &nbsp; }</span></td> </tr> <tr> <th>1650</th><th>1661</th><td class="l"><span></span></td> </tr> </tbody> <tbody class="add"> <tr class="first"> <th>&nbsp;</th><th>1662</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; if( S_OK_IG != CoSetProxyBlanket(</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1663</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pWbemServices,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1664</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RPC_C_AUTHN_DEFAULT_IG,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1665</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RPC_C_AUTHZ_DEFAULT_IG,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1666</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1667</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RPC_C_AUTHN_LEVEL_PKT_IG,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1668</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RPC_C_IMP_LEVEL_IMPERSONATE_IG,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1669</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL,</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1670</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EOAC_NONE_IG</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1671</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1672</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;){</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1673</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;</ins></td> </tr> <tr class=""> <th>&nbsp;</th><th>1674</th><td class="r"><ins>&nbsp; &nbsp; &nbsp; }</ins></td> </tr> <tr class="last"> <th>&nbsp;</th><th>1675</th><td class="r"><ins></ins></td> </tr> </tbody> <tbody class="unmod"> <tr> <th>1651</th><th>1676</th><td class="l"><span>&nbsp; &nbsp; &nbsp; com_releaser&lt;IWbemServices_IG&gt; IWbemServices_releaser(pWbemServices);</span></td> </tr> <tr> <th>1652</th><th>1677</th><td class="l"><span></span></td> </tr> <tr> <th>1653</th><th>1678</th><td class="l"><span>&nbsp; &nbsp; &nbsp; strValue.clear();</span></td> </tr> </tbody> </table> </li> </ul> </div></div> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Sat, 24 Dec 2011 11:11:54 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5552#comment:2 https://svn.boost.org/trac10/ticket/5552#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in trunk, thanks for the patch. From 1.48, use of WMI is disabled, but I would be grateful if someone could enable it again uncommentting </p> <blockquote> <p> #define BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME </p> </blockquote> <blockquote> <p> #define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME </p> </blockquote> <blockquote> <p> #include &lt;boost/interprocess/detail/win32_api.hpp&gt; </p> </blockquote> <p> in detail/tmp_dir_helpders.hpp </p> <p> so that we can enable it again. </p> Ticket