• <i id='LNNBB'><tr id='LNNBB'><dt id='LNNBB'><q id='LNNBB'><span id='LNNBB'><b id='LNNBB'><form id='LNNBB'><ins id='LNNBB'></ins><ul id='LNNBB'></ul><sub id='LNNBB'></sub></form><legend id='LNNBB'></legend><bdo id='LNNBB'><pre id='LNNBB'><center id='LNNBB'></center></pre></bdo></b><th id='LNNBB'></th></span></q></dt></tr></i><div id='LNNBB'><tfoot id='LNNBB'></tfoot><dl id='LNNBB'><fieldset id='LNNBB'></fieldset></dl></div>
  • <small id='LNNBB'></small><noframes id='LNNBB'>

    • <bdo id='LNNBB'></bdo><ul id='LNNBB'></ul>

      <legend id='LNNBB'><style id='LNNBB'><dir id='LNNBB'><q id='LNNBB'></q></dir></style></legend>
    1. <tfoot id='LNNBB'></tfoot>

      1. 无法在 WMI (c++) 中检索对象属性

        时间:2023-12-02

          <tbody id='8H0Wr'></tbody>

            <bdo id='8H0Wr'></bdo><ul id='8H0Wr'></ul>

              <tfoot id='8H0Wr'></tfoot>
            1. <legend id='8H0Wr'><style id='8H0Wr'><dir id='8H0Wr'><q id='8H0Wr'></q></dir></style></legend>
            2. <small id='8H0Wr'></small><noframes id='8H0Wr'>

                  <i id='8H0Wr'><tr id='8H0Wr'><dt id='8H0Wr'><q id='8H0Wr'><span id='8H0Wr'><b id='8H0Wr'><form id='8H0Wr'><ins id='8H0Wr'></ins><ul id='8H0Wr'></ul><sub id='8H0Wr'></sub></form><legend id='8H0Wr'></legend><bdo id='8H0Wr'><pre id='8H0Wr'><center id='8H0Wr'></center></pre></bdo></b><th id='8H0Wr'></th></span></q></dt></tr></i><div id='8H0Wr'><tfoot id='8H0Wr'></tfoot><dl id='8H0Wr'><fieldset id='8H0Wr'></fieldset></dl></div>

                • 本文介绍了无法在 WMI (c++) 中检索对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想用 WMI 做一些事情(接收一些事件通知),所以我从 MSDN 网站上的简单示例开始:

                  I want to do something with WMI (receiving some event notification) so I start with simple example from MSDN website:

                  通过接收事件通知WMI

                  本程序通过WMI接收事件通知(进程创建),并在接收到事件后调用函数EventSink::Indicate.

                  this program receives an event notification (process creation) through WMI, and calls the function EventSink::Indicate upon receiving the event.

                  我在上面的链接(复制/过去)中使用了相同的代码,但做了一个更改:在类 EventSink 中,函数

                  I used the same code in the link above (copy/past) with one change: in the class EventSink, the function

                  HRESULT EventSink::Indicate(long lObjectCount, IWbemClassObject **apObjArray)
                  

                  我添加了几行来检索对象的属性(对象在 apObjArray 中返回):

                  I added few lines to retrieve a property of the object (the object is returned in apObjArray):

                   for (int i = 0; i < lObjectCount; i++)
                      {
                          VARIANT varName;
                          hres = apObjArray[i]->Get(_bstr_t(L"Name"),
                              0, &varName, 0, 0);
                  //...
                      }
                  

                  现在,无论我寻找什么,Get(...) 函数都会返回 WBEM_E_NOT_FOUND(未找到指定的属性)(从文档中可以确定属性在那里...)

                  now the Get(...) functions returns WBEM_E_NOT_FOUND (The specified property is not found) no matter what I look for (am sure from the documentation that the properties are there...)

                  请让我知道我错过了什么?!任何帮助表示赞赏.

                  please let me know what have I missed ?! any help is appreciated.

                  推荐答案

                  Name 属性是 TargetInstance 对象的一部分,因此必须获取 TargetInstance 的值对象,然后检索 Name 属性的值.

                  The Name property is part of the TargetInstance object, so you must get the value of the TargetInstance object and then retrieve the value of the Name property.

                  试试这个样本

                  HRESULT EventSink::Indicate(long lObjectCount,
                      IWbemClassObject **apObjArray)
                  {
                     HRESULT hr = S_OK;
                     _variant_t vtProp;
                  
                      for (int i = 0; i < lObjectCount; i++)
                      {
                  
                      hr = apObjArray[i]->Get(_bstr_t(L"TargetInstance"), 0, &vtProp, 0, 0);
                       if (!FAILED(hr))
                       {
                         IUnknown* str = vtProp;
                         hr = str->QueryInterface( IID_IWbemClassObject, reinterpret_cast< void** >( &apObjArray[i] ) );
                         if ( SUCCEEDED( hr ) )
                         {
                            _variant_t cn;
                           hr = apObjArray[i]->Get( L"Name", 0, &cn, NULL, NULL );
                            if ( SUCCEEDED( hr ) )
                            {
                              if ((cn.vt==VT_NULL) || (cn.vt==VT_EMPTY))
                               wcout << "Name : " << ((cn.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
                              else
                               wcout << "Name : " << cn.bstrVal << endl;
                            }
                            VariantClear(&cn);
                  
                  
                         }
                       }
                       VariantClear(&vtProp);
                  
                      }
                  
                      return WBEM_S_NO_ERROR;
                  }
                  

                  这篇关于无法在 WMI (c++) 中检索对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Windows 10 Toast 通知桌面应用程序 下一篇:使用来自桌面应用程序的 Windows 8 Toast 通知

                  相关文章

                  • <bdo id='TU0b7'></bdo><ul id='TU0b7'></ul>
                  <legend id='TU0b7'><style id='TU0b7'><dir id='TU0b7'><q id='TU0b7'></q></dir></style></legend>

                      <i id='TU0b7'><tr id='TU0b7'><dt id='TU0b7'><q id='TU0b7'><span id='TU0b7'><b id='TU0b7'><form id='TU0b7'><ins id='TU0b7'></ins><ul id='TU0b7'></ul><sub id='TU0b7'></sub></form><legend id='TU0b7'></legend><bdo id='TU0b7'><pre id='TU0b7'><center id='TU0b7'></center></pre></bdo></b><th id='TU0b7'></th></span></q></dt></tr></i><div id='TU0b7'><tfoot id='TU0b7'></tfoot><dl id='TU0b7'><fieldset id='TU0b7'></fieldset></dl></div>

                      <small id='TU0b7'></small><noframes id='TU0b7'>

                      <tfoot id='TU0b7'></tfoot>