通过WMI的方式去设置LCD背光亮度
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;
}
通过WMI的方式去设置LCD背光亮度的更多相关文章
- 十二、使用PWM调整LCD背光亮度
和手机一样,开发板中也带有调整背光亮度的功能. 调整背光亮度依赖于PWM,它通过调节脉冲宽度来控制背光亮度,此方式需要使用PWM驱动.本章将对其进行讲解. 一.用户空间调整背光亮度 一般应用程序可以通 ...
- [LED]如何配置LCD背光和LED,调试方法
[DESCRIPTION] 如何配置LCD背光和LED,调试方法 [SOLUTION]LCD背光和LED配置文件alps/custom/<proj name>lk/cust_leds.ca ...
- 如何配置LCD背光和LED,调试方法
LCD背光和LED配置文件 alps/custom/<proj name>lk/cust_leds.c alps/custom/<proj name>/kernel/leds/ ...
- 使用IOCTL代码实现LCD背光调节
国内这种代码找不到.于是參考了相关代码后完好例如以下代码,且实现方式通过IOCTL代码实现LCD背光调节的功能. 适合场合为平板电脑或者笔记本.主要还是要靠BIOS支持与否. 编译环境使用:Dev-c ...
- amba H2平台用PWM控制LCD背光
ambarella H2系列Soc的GPIO口能作PWM使用的个数有限(GPIO0-GPIO3),从PRM里GPIO: Function Selection章节可以得到如何配置GPIO为PWM功能. ...
- 用Window Authentication的方式去连接SQLServer
用Window Authentication的方式去连接SQLServer Connection String: jdbc:sqlserver://${serverName};databaseName ...
- iOS开发UI篇—ios应用数据存储方式(偏好设置)
iOS开发UI篇—ios应用数据存储方式(偏好设置) 一.简单介绍 很多iOS应用都支持偏好设置,比如保存用户名.密码.字体大小等设置,iOS提供了一套标准的解决方案来为应用加入偏好设置功能 每个应用 ...
- 12Mybatis_用mapper代理的方式去开发以及总结mapper开发的一些问题
上一篇文章总结了一些Dao开发的问题,所以我们这里开始讲一种mapper代理的方式去开发. 我先给出mapper代理开发的思路(mapper代理开发的规范): 我们用mapper代理开发时要写2个: ...
- paip.无线路由器的无线接入WAN方式WDS设置大法
paip.无线路由器的无线接入WAN方式WDS设置大法 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn. ...
随机推荐
- 入门Python:《趣学Python编程》中英文PDF+代码
入门python推荐学习<趣学python编程>,语言轻松,通俗易懂,讲解由浅入深,力求将读者阅读和学习的难度降到最低.任何对计算机编程有兴趣的人或者首次接触编程的人,不论孩子还是成人,都 ...
- Yeslab 华为安全HCIE-第五门-防火墙攻击防范技术
Yeslab 华为安全HCIE-第五门-防火墙攻击防范技术 课程目录 Yeslab华为安全HCIE-第五门-防火墙攻击防范技术(8篇)\1_单包攻击防范.aviYeslab华为安全HCIE-第五门-防 ...
- MYSQL查询数据中通讯最多的两个人
SELECT GREATEST( sender_id, recipient_id ) , LEAST( sender_id, recipient_id ) , COUNT( * ) AS aFROM ...
- 【Henu ACM Round#16 A】 Bear and Game
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 看看什么时候t[i]-t[i-1]>15. 输出t[i-1]+15就好. 不存在这样的i就输出min(t[n]+15,90) ...
- javap 命令 反编译代码
javap 命令 javap -c classname 一个好的分析class二进制文件的 链接 http://blog.csdn.net/pwlazy/article/details/7954169
- buffer--cache 详解
- 负载均衡之lvs
集群(cluster):将一组计算机软/硬件连接起来,高度紧密的协作完成计算工作,其中的单个计算机通常称为节点.负载均衡集群(Load Balancing):通过负载均衡器,将负载尽可能平均分摊处理. ...
- 【Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined) A】 Perfect Squares
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] N*1000暴力就好 [代码] #include <bits/stdc++.h> using namespace std ...
- 【习题 8-13 UVA - 10570】Meeting with Aliens
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举1的位置在i 往右摆成一排. a[i+1]..a[n]..a[1]..a[i-1]变为有序的 ->寻找循环节,每个循环节的 ...
- 自己动手写SSO(单点登录)
SSO在我们的应用中非常常见,例如我们在OA系统登录了,我们就可以直接进入采购系统,不需要再登录了,这样使我们非常方便.现在网上也有很多实现方法,于是乎我也想写一个看看.我主要用到的是cookie的机 ...