查询 D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY 的 WMI [英] Querying WMI for D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY

查看:23
本文介绍了查询 D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY 的 WMI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关注了这篇 MSDN 文章,该文章显示了从本地计算机检索 WMI 数据的示例 http://msdn.microsoft.com/en-us/library/windows/desktop/aa390423%28v=vs.85%29.aspx

I have followed this MSDN article which shows an example of retrieving WMI data from the local computer http://msdn.microsoft.com/en-us/library/windows/desktop/aa390423%28v=vs.85%29.aspx

显示的示例获取操作系统的名称,但在我的情况下,我查询从 WmiMonitorConnectionParams 中选择 *"并希望检索 D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY http://msdn.microsoft.com/en-us/library/windows/hardware/ff546605%28v=vs.85%29.aspx

The example shown gets the name of the operating system, but in my case I am querying "Select * from WmiMonitorConnectionParams" and want to retrieve the D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY http://msdn.microsoft.com/en-us/library/windows/hardware/ff546605%28v=vs.85%29.aspx

在这种情况下我应该如何使用 IWbemClassObject::Get?VARIANT 变量的哪个成员存储了我想要的结果?

How should I use IWbemClassObject::Get in this case? And which member of the VARIANT variable stores the result that I'm after?

更一般地说,我们应该如何知道在每次查询之后在 Get 方法中使用哪些标志以及 VARIANT 的哪个成员存储结果?这是在哪里记录的?

More generally, how are we supposed to know what flags to use in the Get method after each query and which member of the VARIANT stores the result? Where is this documented?

谢谢.

推荐答案

是的,您必须使用 IWbemClassObject 检索数据的接口,关于要使用的变体成员,取决于WMI属性的类型,在这种情况下 VideoOutputTechnology 属性是一个 uint32 值,因此您必须使用 uintVal 成员.

Yes, you must use the IWbemClassObject interface to retrieve the data, about the variant member to use, it's depend of the type of the WMI property, in this case the VideoOutputTechnology property is a uint32 value, so you must use the uintVal member.

检查此示例代码

#include "stdafx.h"
#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h>
# pragma comment(lib, "wbemuuid.lib")


// Monitor's basic connection parameters

#pragma argsused
int main(int argc, char* argv[])
{
    BSTR strNetworkResource;
    //To use a WMI remote connection set localconn to false and configure the values of the pszName, pszPwd and the name of the remote machine in strNetworkResource
    strNetworkResource = L"\\\\.\\root\\WMI";

    COAUTHIDENTITY *userAcct =  NULL ;
    COAUTHIDENTITY authIdent;

    // Initialize COM. ------------------------------------------

    HRESULT hres;
    hres =  CoInitializeEx(0, COINIT_MULTITHREADED);
    if (FAILED(hres))
    {
        cout << "Failed to initialize COM library. Error code = 0x" << hex << hres << endl;
        cout << _com_error(hres).ErrorMessage() << endl;
        cout << "press enter to exit" << endl;
        cin.get();      
        return 1;                  // Program has failed.
    }

    // Set general COM security levels --------------------------

        hres =  CoInitializeSecurity(
            NULL,
            -1,                          // COM authentication
            NULL,                        // Authentication services
            NULL,                        // Reserved
            RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication
            RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
            NULL,                        // Authentication info
            EOAC_NONE,                   // Additional capabilities
            NULL                         // Reserved
            );

    if (FAILED(hres))
    {
        cout << "Failed to initialize security. Error code = 0x" << hex << hres << endl;
        cout << _com_error(hres).ErrorMessage() << endl;
        CoUninitialize();
        cout << "press enter to exit" << endl;
        cin.get();      
        return 1;                    // Program has failed.
    }

    // Obtain the initial locator to WMI -------------------------

    IWbemLocator *pLoc = NULL;
    hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);

    if (FAILED(hres))
    {
        cout << "Failed to create IWbemLocator object." << " Err code = 0x" << hex << hres << endl;
        cout << _com_error(hres).ErrorMessage() << endl;
        CoUninitialize();       
        cout << "press enter to exit" << endl;
        cin.get();      
        return 1;                 // Program has failed.
    }

    // Connect to WMI through the IWbemLocator::ConnectServer method

    IWbemServices *pSvc = NULL;

        hres = pLoc->ConnectServer(
             _bstr_t(strNetworkResource),      // Object path of WMI namespace
             NULL,                    // User name. NULL = current user
             NULL,                    // User password. NULL = current
             0,                       // Locale. NULL indicates current
             NULL,                    // Security flags.
             0,                       // Authority (e.g. Kerberos)
             0,                       // Context object
             &pSvc                    // pointer to IWbemServices proxy
             );

    if (FAILED(hres))
    {
        cout << "Could not connect. Error code = 0x" << hex << hres << endl;    
        cout << _com_error(hres).ErrorMessage() << endl;
        pLoc->Release();
        CoUninitialize();
        cout << "press enter to exit" << endl;
        cin.get();          
        return 1;                // Program has failed.
    }

    cout << "Connected to root\\WMI WMI namespace" << endl;

    // Set security levels on the proxy -------------------------
        hres = CoSetProxyBlanket(
           pSvc,                        // Indicates the proxy to set
           RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
           RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
           NULL,                        // Server principal name
           RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx
           RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
           NULL,                        // client identity
           EOAC_NONE                    // proxy capabilities
        );

    if (FAILED(hres))
    {
        cout << "Could not set proxy blanket. Error code = 0x" << hex << hres << endl;
        cout << _com_error(hres).ErrorMessage() << endl;
        pSvc->Release();
        pLoc->Release();
        CoUninitialize();
        cout << "press enter to exit" << endl;
        cin.get();      
        return 1;               // Program has failed.
    }

    // Use the IWbemServices pointer to make requests of WMI ----

    IEnumWbemClassObject* pEnumerator = NULL;
    hres = pSvc->ExecQuery( L"WQL", L"SELECT * FROM WmiMonitorConnectionParams",
    WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);

    if (FAILED(hres))
    {
        cout << "ExecQuery failed" << " Error code = 0x"    << hex << hres << endl;
        cout << _com_error(hres).ErrorMessage() << endl;
        pSvc->Release();
        pLoc->Release();
        CoUninitialize();
        cout << "press enter to exit" << endl;
        cin.get();      
        return 1;               // Program has failed.
    }


    // Get the data from the WQL sentence
    IWbemClassObject *pclsObj = NULL;
    ULONG uReturn = 0;

    while (pEnumerator)
    {
        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);

        if(0 == uReturn || FAILED(hr))
          break;

        VARIANT vtProp;

                hr = pclsObj->Get(L"Active", 0, &vtProp, 0, 0);// Boolean
                if (!FAILED(hr))
                {
                  if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
                    wcout << "Active : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
                  else
                    wcout << "Active : " << (vtProp.boolVal ? "True" : "False") << endl;
                }
                VariantClear(&vtProp);

                hr = pclsObj->Get(L"InstanceName", 0, &vtProp, 0, 0);// String
                if (!FAILED(hr))
                {
                  if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
                    wcout << "InstanceName : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
                  else
                    wcout << "InstanceName : " << vtProp.bstrVal << endl;
                }
                VariantClear(&vtProp);

                hr = pclsObj->Get(L"VideoOutputTechnology", 0, &vtProp, 0, 0);// Uint32
                if (!FAILED(hr))
                {
                  if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
                    wcout << "VideoOutputTechnology : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
                  else
                    wcout << "VideoOutputTechnology : " << vtProp.uintVal << endl;
                }
                VariantClear(&vtProp);


        pclsObj->Release();
        pclsObj=NULL;
    }

    // Cleanup

    pSvc->Release();
    pLoc->Release();
    pEnumerator->Release();
    if (pclsObj!=NULL)
     pclsObj->Release();

    CoUninitialize();
    cout << "press enter to exit" << endl;
    cin.get();
    return 0;   // Program successfully completed.
}

您也可以使用像 wmi delphi code creator 可以帮助您探索 WMI 并生成 C++ 代码来访问 WMI 数据.

Also you can use a tool like the wmi delphi code creator which can help you to explore the WMI and generate C++ code to access the WMI Data.

这篇关于查询 D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY 的 WMI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆