通过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. ...
随机推荐
- 【VC++学习笔记一】MFC操作Excel
最近在做一个读取Excel的功能,之前也做过相关的,但总是零零闪闪的,趁着正在劲头上,归纳一下: 利用Automation添加相关的类,在Excel2010中可以在安装文件夹下直接点击Excel.ex ...
- Linux发行版centos, ubuntu等
公司装的是centos,centos其实就是无支持版的redhat. redhat是一个服务器的操作系统它的稳定性是比较高的,同时提供在线管理服务,服务器故障预警等,当然前提是要购买昂贵的服务. Su ...
- 关于Java的10个谎言
以下的这些都算是比較高级的问题了.面试中一般也非常少问到.由于它们可能会把面试者拒之门外.只是你能够自己找个时间来实践一下. System.exit(0)会跳过finally块的运行 System.s ...
- GO语言为结构体排序
package main import ( "fmt" "io/ioutil" "sort" "time" ) type ...
- 如何使用jquery判断一个元素是否含有一个指定的类(class)
如何使用jquery判断一个元素是否含有一个指定的类(class) 一.总结 一句话总结:可以用hasClass方法(专用)和is方法 1.is(expr|obj|ele|fn)的方法几个参数表示什么 ...
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第六章 2(Binary Trees)
112 - Tree Summing 题目大意:给出一个数,再给一颗树,每个头节点的子树被包含在头节点之后的括号里,寻找是否有从头节点到叶子的和与给出的数相等,如果有则输出yes,没有输出no! 解题 ...
- 分享一个vue常用的ui控件
vue学习文档 http://www.jianshu.com/p/8a272fc4e8e8 vux github ui demo:https://github.com/airyland/vux M ...
- 玲珑学院 1014 Absolute Defeat
SAMPLE INPUT 3 2 2 2 1 1 5 1 4 1 2 3 4 5 4 10 3 1 2 3 4 SAMPLE OUTPUT 1 0 15 前缀和,每个元素都判断一下. #include ...
- python hmac 加密
python2 : key 是秘钥 类型为 str msg 要加密的文件 str digestmod 要加密的方式 python3: key 是秘钥 类型为 byte msg 要加密的文件 byte ...
- 下载编译 Android wear 源代码,尝试制作可穿戴设备功能
体验 Android Wear 缘由: Android wear 代码公布已经非常久了.一直没有尝试,这里是个编译的过程和步骤,假设要尝试.本文假定读者已经有下载编译 Android 的经验,假设没 ...