Windows客户端开发--使用WMI获取显卡详细信息(win32控制台程序)
来源:互联网 发布:windows 2012装snmp 编辑:程序博客网 时间:2024/06/08 02:06
昨天接受了WMI的基础知识,因为自己也是刚刚接触,也是应用型的,没有研究的更深更透。
今天,就写一个真是的例子吧。
比如说,我们要获得计算机显示适配器的详细信息,包括显卡的型号,显卡驱动的版本号,以及显卡当前的状态。
Win32_VideoController
class Win32_VideoController : CIM_PCVideoController{uint16 AcceleratorCapabilities[];string AdapterCompatibility;string AdapterDACType;uint32 AdapterRAM;uint16 Availability;string CapabilityDescriptions[];string Caption;uint32 ColorTableEntries;uint32 ConfigManagerErrorCode;boolean ConfigManagerUserConfig;string CreationClassName;uint32 CurrentBitsPerPixel;uint32 CurrentHorizontalResolution;uint64 CurrentNumberOfColors;uint32 CurrentNumberOfColumns;uint32 CurrentNumberOfRows;uint32 CurrentRefreshRate;uint16 CurrentScanMode;uint32 CurrentVerticalResolution;string Description;string DeviceID;uint32 DeviceSpecificPens;uint32 DitherType;datetime DriverDate;string DriverVersion;boolean ErrorCleared;string ErrorDescription;uint32 ICMIntent;uint32 ICMMethod;string InfFilename;string InfSection;datetime InstallDate;string InstalledDisplayDrivers;uint32 LastErrorCode;uint32 MaxMemorySupported;uint32 MaxNumberControlled;uint32 MaxRefreshRate;uint32 MinRefreshRate;boolean Monochrome;string Name;uint16 NumberOfColorPlanes;uint32 NumberOfVideoPages;string PNPDeviceID;uint16 PowerManagementCapabilities[];boolean PowerManagementSupported;uint16 ProtocolSupported;uint32 ReservedSystemPaletteEntries;uint32 SpecificationVersion;string Status;uint16 StatusInfo;string SystemCreationClassName;string SystemName;uint32 SystemPaletteEntries;datetime TimeOfLastReset;uint16 VideoArchitecture;uint16 VideoMemoryType;uint16 VideoMode;string VideoModeDescription;string VideoProcessor;};
英文看着费劲是吗:
AcceleratorCapabilities --图形和视频控制器的三维阵列的能力AdapterCompatibility --用于此控制器与系统比较兼容性一般芯片组AdapterDACType --姓名或数字 - 模拟转换器(DAC)芯片的标识符AdapterRAM --视频适配器的内存大小Availability --可用性和设备的状态CapabilityDescriptions --自由形式字符串提供更详细的解释中的任何加速器能力阵列所指示的视频加速器功能Caption --对象的简短描述ColorTableEntries --尺寸系统的色表ConfigManagerErrorCode --Win32的配置管理器错误代码ConfigManagerUserConfig --如果为TRUE,该装置是使用用户定义的配置CreationClassName --第一个具体类的名称出现在创建实例所使用的继承链CurrentBitsPerPixel --使用的比特数以显示每个像素CurrentHorizontalResolution --水平像素的当前数量CurrentNumberOfColors --在当前的分辨率支持的色彩数目CurrentNumberOfColumns --此视频控制器列(如果在字符模式下)编号CurrentNumberOfRows --此视频控制器行(如果在字符模式下)编号CurrentRefreshRate --频率在该视频控制器刷新监视器的图像CurrentScanMode --当前扫描模式CurrentVerticalResolution --当前垂直像素数量Description --描述DeviceID --该视频控制器标识符(唯一的计算机系统)DeviceSpecificPens --目前许多设备专用笔。值0xFFFF表示设备不支持笔。DitherType --抖动型视频控制器DriverDate --当前已安装的视频驱动程序的最后修改日期和时间DriverVersion --视频驱动程序的版本号ErrorCleared --如果为真,报上一个错误代码属性中的错误现已清除ErrorDescription --可能采取的纠正措施字符串提供有关记录在一个错误代码属性错误的详细信息ICMIntent --应使用默认三种可能的配色方法或意图中的一个特定值ICMMethod --处理ICM方法。对于非ICM的应用程序,这个属性决定了ICM是否已启用对于ICM的应用程序,系统将检查此属性来确定如何处理ICM支持InfFilename --视频适配器的路径.inf文件InfSection --Windows的视频信息所在的.inf文件InstallDate --安装的日期InstalledDisplayDrivers --已安装的显示设备驱动程序的名称LastErrorCode --报告的逻辑设备上一个错误代码 MaxMemorySupported --以字节为单位支持的内存最高限额MaxNumberControlled --可支持通过该控制器可直接寻址的实体的最大数量MaxRefreshRate --在赫兹视频控制器的最大刷新率MinRefreshRate --在赫兹视频控制器的最小刷新率Monochrome --如果是TRUE,灰阶用于显示图像。Name --标签由该对象是已知的。当子类,该属性可以被覆盖是一个关键属性。NumberOfColorPlanes --当前一些颜色平面。如果该值不适用于当前视频的配置,输入0(零)NumberOfVideoPages --当前的分辨率和可用内存支持视频页数PNPDeviceID --即插即用逻辑设备的播放装置识别符PowerManagementCapabilities --逻辑设备的特定功率相关的能力阵列PowerManagementSupported --如果为TRUE,该装置可以是电源管理(可以投入挂起模式,等等)ProtocolSupported --由控制器使用协议访问“控制”的设备ReservedSystemPaletteEntries --系统调色板保留的条目数SpecificationVersion --初始化数据规范的版本号(在其上的结构的基础)Status --对象的当前状态StatusInfo --对象的当前状态详细信息SystemCreationClassName --该作用域计算机的创建类别名称属性的值SystemName --系统的名称SystemPaletteEntries --当前一些系统调色板颜色索引条目TimeOfLastReset --该控制器是最后一次复位日期和时间,这可能意味着该控制器被断电或重新初始化VideoArchitecture --视频体系结构的类型VideoMemoryType --显存类型VideoMode --当前视频模式VideoModeDescription --当前的分辨率,颜色和视频控制器的扫描模式设置VideoProcessor --无格式的字符串描述视频处理器
获取计算机显卡详细信息,全部代码:
#define _WIN32_DCOM#include <iostream>using namespace std;#include <comdef.h>#include <Wbemidl.h>#include <string>#pragma comment(lib, "wbemuuid.lib")int main(int argc, char **argv){ HRESULT hres; // Initialize COM. hres = CoInitializeEx(0, COINIT_APARTMENTTHREADED); if (FAILED(hres)) { cout << "Failed to initialize COM library. " << "Error code = 0x" << hex << hres << endl; return 1; // Program has failed. } // Initialize hres = CoInitializeSecurity( NULL, -1, // COM negotiates service NULL, // Authentication services NULL, // Reserved RPC_C_AUTHN_LEVEL_DEFAULT, // authentication RPC_C_IMP_LEVEL_IMPERSONATE, // Impersonation NULL, // Authentication info EOAC_NONE, // Additional capabilities NULL // Reserved ); if (FAILED(hres)) { cout << "Failed to initialize security. " << "Error code = 0x" << hex << hres << endl; CoUninitialize(); return 1; // Program has failed. } // Obtain the initial locator to Windows Management // on a particular host computer. IWbemLocator *pLoc = 0; hres = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *)&pLoc); if (FAILED(hres)) { cout << "Failed to create IWbemLocator object. " << "Error code = 0x" << hex << hres << endl; CoUninitialize(); return 1; // Program has failed. } IWbemServices *pSvc = 0; // Connect to the root\cimv2 namespace with the // current user and obtain pointer pSvc // to make IWbemServices calls. hres = pLoc->ConnectServer( _bstr_t(L"ROOT\\CIMV2"), // WMI namespace NULL, // User name NULL, // User password 0, // Locale NULL, // Security flags 0, // Authority 0, // Context object &pSvc // IWbemServices proxy ); if (FAILED(hres)) { cout << "Could not connect. Error code = 0x" << hex << hres << endl; pLoc->Release(); CoUninitialize(); return 1; // Program has failed. } cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl; // Set the IWbemServices proxy so that impersonation // of the user (client) occurs. hres = CoSetProxyBlanket( pSvc, // the proxy to set RPC_C_AUTHN_WINNT, // authentication service RPC_C_AUTHZ_NONE, // authorization service NULL, // Server principal name RPC_C_AUTHN_LEVEL_CALL, // authentication level RPC_C_IMP_LEVEL_IMPERSONATE, // impersonation level NULL, // client identity EOAC_NONE // proxy capabilities ); if (FAILED(hres)) { cout << "Could not set proxy blanket. Error code = 0x" << hex << hres << endl; pSvc->Release(); pLoc->Release(); CoUninitialize(); return 1; // Program has failed. } // Use the IWbemServices pointer to make requests of WMI. // Make requests here: // For example, query for all the running processes IEnumWbemClassObject* pEnumerator = NULL; hres = pSvc->ExecQuery( bstr_t("WQL"), bstr_t("SELECT * FROM Win32_VideoController"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); if (FAILED(hres)) { cout << "Query for processes failed. " << "Error code = 0x" << hex << hres << endl; pSvc->Release(); pLoc->Release(); CoUninitialize(); return 1; // Program has failed. } else { IWbemClassObject *pclsObj; ULONG uReturn = 0; while (pEnumerator) { hres = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); if (0 == uReturn) { break; } VARIANT vtProp; VARIANT vtProp2; // Get the value of the Name property hres = pclsObj->Get(L"Description", 0, &vtProp, 0, 0); WCHAR* des; des = vtProp.bstrVal; wcout << "Description: " << vtProp.bstrVal << endl; hres = pclsObj->Get(L"Availability", 0, &vtProp2, 0, 0); wcout << "Availability: " << vtProp2.uintVal << endl; VariantClear(&vtProp); VariantClear(&vtProp2); } } // Cleanup // ======== pSvc->Release(); pLoc->Release(); CoUninitialize(); return 0; }
无图无真相,运行结果:
注意
wcout << “Description: ” << vtProp.bstrVal << endl;
wcout << “Availability: ” << vtProp2.uintVal << endl;
解析的时候类型不用弄错了bstrVal或是uintVal
2 0
- Windows客户端开发--使用WMI获取显卡详细信息(win32控制台程序)
- 使用WMI获取远程机器操作系统的详细信息
- Windows客户端开发--WMI技术介绍
- 查看windows显卡内存详细信息
- 【PERL】使用wmi获取windows硬件信息
- 在Win32控制台程序中使用定时器
- win32控制台程序里面,使用CString
- windows控制台程序使用TIMER
- wmi使用的win32类库名
- Win32控制台程序是什么
- Win32控制台程序是什么
- Win32控制台程序是什么
- Win32控制台程序是什么
- Win32控制台程序是什么
- Win32控制台程序是什么
- Win32控制台程序如何获取MFC库支持
- windows API编程之二----控制台模拟Win32程序
- 在Win32控制台程序中添加Windows窗口
- java----IO流
- facebook工具xhprof的安装与使用-分析php执行性能
- Linux学习笔记六-shell
- 浅谈服务化
- IDEA 2016在创建spring项目时遇到的坑
- Windows客户端开发--使用WMI获取显卡详细信息(win32控制台程序)
- Stack介绍
- string类型
- Nodejs学习路线图
- Vue.js学习 Item7 -- 条件渲染与列表渲染
- Window下使用aria2c进行多线程进行文件下载
- 举例详解PHP归并排序的实现
- 基于java过滤器实现web系统的IP访问控制
- Nginx + Tomcat 动静分离实现负载均衡