通过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. ...
随机推荐
- vuex的mutations如何传多个传参?
1.不传参时的写法(官网例子): const store = new Vuex.Store({ state: { count: 1 }, mutations: { increment (state) ...
- 计算机科学书籍推荐和CSS、js书籍推荐
计算机科学:<深入理解计算机系统>,这是基础知识 JavaScript:JavaScript高级程序设计:大名鼎鼎的红宝书 <精通CSS:高级Web标准解决方案>:因为我觉CS ...
- selenium使用报错“selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.”
安装了python3,使用pip安装了selenium,但是在使用时,报了“selenium.common.exceptions.WebDriverException: Message: 'gecko ...
- @Mapper 和 @MapperScan 区别
1.@Mapper : 为了使接口被其他类引用,需要使用@Mapper注解,这种方式要求每一个mapper类都需要添加此注解,麻烦. package com.example.demo.dao; imp ...
- Codeforces Beta Round #2 C. Commentator problem
模拟退火果然是一个非常高端的东西,思路神马的全然搞不懂啊~ 题目大意: 给出三个圆,求一点到这三个圆的两切线的夹角相等. 解题思路: 对于这个题来说还是有多种思路的 .只是都搞不明确~~ /害羞脸 ...
- final使用方法
final的作用随着所修饰的类型而不同 1.final修饰类中的属性或者变量 不管属性是基本类型还是引用类型.final所起的作用都是变量里面存放的"值"不能变. 这个值,对 ...
- 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)
[POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
- html --- bootstrap 框架 (栅格系统布局)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#导出EXCEL(DataTable导出EXCEL)
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.I ...
- c# List集合学习
1---集合,可以理解成容器 泛型集合 非泛型集合2---使用集合用到的命名空间 using System.Collections.Generic;3---集合是如何来的?集合的前辈是数组,数组在内存 ...