通过WMI的方式去设置LCD背光亮度
2024-09-24 20:10:11
code例如以下:
#include "stdafx.h"
#include <objbase.h>
#include <windows.h>
#include <stdio.h>
#include <wbemidl.h>
#include <comdef.h> #pragma comment(lib, "wbemuuid.lib")
#pragma comment(lib, "comsuppw.lib") int _tmain(int argc, _TCHAR* argv[])
{
IWbemLocator * pLocator = NULL;
IWbemServices * pNamespace = 0;
IWbemClassObject * pClass = NULL;
IWbemClassObject * pInClass = NULL;
IWbemClassObject * pInInst = NULL;
IEnumWbemClassObject *pEnum = NULL;
HRESULT hr = S_OK; BSTR path = SysAllocString(L"root\\wmi");
BSTR ClassPath = SysAllocString(L"WmiMonitorBrightnessMethods");
BSTR MethodName = SysAllocString(L"WmiSetBrightness");
BSTR ArgName0 = SysAllocString(L"Timeout");
BSTR ArgName1 = SysAllocString(L"Brightness");
BSTR bstrQuery = SysAllocString(L"Select * from WmiMonitorBrightnessMethods"); if (!path || ! ClassPath || !MethodName || ! ArgName0)
{
printf("SysAllocString failed. Out of memory.\n");
{printf("\n[-] Err: xxx");goto cleanup;}
} // Initialize COM and connect up to CIMOM hr = CoInitialize(0);
if (FAILED(hr))
{
printf("CoInitialize returned 0x%x:", hr);
{printf("\n[-] Err: CoInitialize");goto cleanup;}
} // NOTE:
// When using asynchronous WMI API's remotely in an environment where the "Local System" account
// has no network identity (such as non-Kerberos domains), the authentication level of
// RPC_C_AUTHN_LEVEL_NONE is needed. However, lowering the authentication level to
// RPC_C_AUTHN_LEVEL_NONE makes your application less secure. It is wise to
// use semi-synchronous API's for accessing WMI data and events instead of the asynchronous ones. hr = CoInitializeSecurity(NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE, //change to EOAC_NONE if you change dwAuthnLevel to RPC_C_AUTHN_LEVEL_NONE
NULL );
if (FAILED(hr))
{
printf("CoInitializeSecurity returned 0x%x:", hr);
{printf("\n[-] Err: CoInitializeSecurity");goto cleanup;}
} hr = CoCreateInstance(CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator,
(LPVOID *) &pLocator);
if (FAILED(hr))
{
printf("CoCreateInstance returned 0x%x:", hr);
{printf("\n[-] Err: CoCreateInstance");goto cleanup;}
}
hr = pLocator->ConnectServer(path,
NULL,
NULL,
NULL,
0,
NULL,
NULL,
&pNamespace);
printf("\nConnectServer returned 0x%x:", hr);
if(hr != WBEM_S_NO_ERROR)
{printf("\n[-] Err: ConnectServer");goto cleanup;} hr = CoSetProxyBlanket(pNamespace,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE); if(hr != WBEM_S_NO_ERROR)
{printf("\n[-] Err: CoSetProxyBlanket");goto cleanup;} hr =pNamespace->ExecQuery(_bstr_t(L"WQL"), //Query Language
bstrQuery, //Query to Execute
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, //Make a semi-synchronous call
NULL, //Context
&pEnum /*Enumeration Interface*/); if(hr != WBEM_S_NO_ERROR)
{printf("\n[-] Err: ExecQuery");goto cleanup;} hr = WBEM_S_NO_ERROR; ULONG ulReturned;
IWbemClassObject *pObj;
DWORD retVal = 0; //Get the Next Object from the collection
hr = pEnum->Next(WBEM_INFINITE, //Timeout
1, //No of objects requested
&pObj, //Returned Object
&ulReturned /*No of object returned*/); if(hr != WBEM_S_NO_ERROR)
{printf("\n[-] Err: Next");goto cleanup;} // Get the class object
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);
printf("\nGetObject returned 0x%x:", hr);
if(hr != WBEM_S_NO_ERROR)
{printf("\n[-] Err: GetObject");goto cleanup;} // Get the input argument and set the property
hr = pClass->GetMethod(MethodName, 0, &pInClass, NULL);
printf("\nGetMethod returned 0x%x:", hr);
if(hr != WBEM_S_NO_ERROR)
{printf("\n[-] Err: GetMethod");goto cleanup;} hr = pInClass->SpawnInstance(0, &pInInst);
printf("\nSpawnInstance returned 0x%x:", hr);
if(hr != WBEM_S_NO_ERROR)
{printf("\n[-] Err: SpawnInstance");goto cleanup;} VARIANT var1;
VariantInit(&var1); V_VT(&var1) = VT_BSTR;
V_BSTR(&var1) = SysAllocString(L"0");
hr = pInInst->Put(ArgName0,
0,
&var1,
CIM_UINT32); //CIM_UINT64 //var1.vt = VT_I4;
//var1.ullVal = 0;
//hr = pInInst->Put(ArgName0, 0, &var1, 0);
printf("\nPut ArgName0 returned 0x%x:", hr);
VariantClear(&var1);
if(hr != WBEM_S_NO_ERROR)
{printf("\n[-] Err: Put ArgName0");goto cleanup;} VARIANT var;
VariantInit(&var); V_VT(&var) = VT_BSTR;
V_BSTR(&var) = SysAllocString(L"100");
hr = pInInst->Put(ArgName1,
0,
&var,
CIM_UINT8); //var.vt=VT_UI1;
//var.uiVal = 100;
//hr = pInInst->Put(ArgName1, 0, &var, 0);
VariantClear(&var);
printf("\nPut ArgName1 returned 0x%x:", hr);
if(hr != WBEM_S_NO_ERROR)
{printf("\n[-] Err: Put ArgName1");goto cleanup;}
// Call the method VARIANT pathVariable;
VariantInit(&pathVariable); hr = pObj->Get(_bstr_t(L"__PATH"),
0,
&pathVariable,
NULL,
NULL);
printf("\npObj Get returned 0x%x:", hr);
if(hr != WBEM_S_NO_ERROR)
{printf("\n[-] Err: Get");goto cleanup;} hr =pNamespace->ExecMethod(pathVariable.bstrVal,
MethodName,
0,
NULL,
pInInst,
NULL,
NULL);
VariantClear(&pathVariable);
printf("\nExecMethod returned 0x%x:", hr);
if(hr != WBEM_S_NO_ERROR)
{printf("\n[-] Err: ExecMethod");goto cleanup;} printf("Terminating normally\n"); // Free up resources
cleanup:
SysFreeString(path);
SysFreeString(ClassPath);
SysFreeString(MethodName);
SysFreeString(ArgName0);
SysFreeString(ArgName1);
SysFreeString(bstrQuery); if (pClass) pClass->Release();
if (pInInst) pInInst->Release();
if (pInClass) pInClass->Release();
if (pLocator) pLocator->Release();
if (pNamespace) pNamespace->Release(); CoUninitialize(); return 0;
}
最新文章
- NoSQL生态系统——一致性RWN协议,向量时钟,gossip协议监测故障
- CardView的简单介绍
- nodejs配置与入门
- 调试 Azure 云服务项目的方法
- PHP冒泡排序,选择排序,插入排序
- sun.misc.BASE64Encoder找不到包,解决方法
- boost xpressive 例子
- python 九九乘法表!小练习
- web站点优化之使用tengine搭建静态资源服务器,静态资源合并加载案例剖析
- 附录D——自动微分(Autodiff)
- Fork别人的代码 原作者更新后如何同步
- Android--UI之Radio、Check、Toggle
- {python之IO多路复用} IO模型介绍 阻塞IO(blocking IO) 非阻塞IO(non-blocking IO) 多路复用IO(IO multiplexing) 异步IO(Asynchronous I/O) IO模型比较分析 selectors模块
- How to fix ";http error 403.14 - forbidden"; in IIS7
- VS2013 此模板尝试加载组件程序集&rdquo;NuGet.VisualStudio.interop,Version=1.0.0.0 的解决办法
- SQL中MAX()和MIN()函数的使用(比较字符串的大小)
- 51地图标注接口(EZMarker API)
- 王者荣耀交流协会第一次Scrum立会
- Grid++Report 注册
- apache ab测试
热门文章
- WP8 学习笔记(001_环境配置)
- TI Code Composer Studio MSP430系列驱动源代码
- java设计模式--事件监听器模式和观察者模式
- Swift vs C# Go OC
- java8新增特性(一)---Lambda表达式
- Oracle HR 例子用户的建立 10g,11g均可
- Lua 是一个小巧的脚本语言
- 使用h5 <;a>;标签 href=&#39;url&#39; download 下载踩过的坑
- BFC的布局规则和触发条件
- learn ES6