问题描述
我在Windows Server 2008上安装了一台索尼笔记本电脑和亮度控制不起作用。我想编写一个程序,让我去改变它。
I have Windows Server 2008 installed on a Sony laptop and the brightness control doesn't work. I'd like to write a program to allow me to change it.
目前我所要做的就是打开电源控制面板上,点击高级设置,并通过这么多的UAC框打,任何人都看着我必须想我完全疯了。
Currently what I have to do is open the Power control panel, click advanced settings, and fight through so many UAC boxes that anybody watching me must think I'm completely crazy.
我只想要一个简单的小程序来做到这一点,但我不知道什么叫API
I just want a simple little program to do it but i dont know what API to call
推荐答案
我抬头一看John鲁迪的链接 WmiSetBrightness MSDN中,并提出了这一点:
I looked up John Rudy's link to WmiSetBrightness in MSDN and came up with this:
ManagementClass mclass = new ManagementClass("WmiMonitorBrightnessMethods");
mclass.Scope = new ManagementScope(@"\\.\root\wmi");
ManagementObjectCollection instances = mclass.GetInstances();
// I assume you get one instance per monitor
foreach(ManagementObject instance in instances)
{
ulong timeout = 1; // in seconds
ushort brightness = 50; // in percent
object[] args = new object[] { timeout, brightness };
instance.InvokeMethod("WmiSetBrightness", args);
}
注: ManagementClass
, ManagementObjectCollection
和的ManagementObject
所有实施的IDisposable
。你应该叫的Dispose()
,或者使用使用
,以避免泄露的资源。
Note: ManagementClass
, ManagementObjectCollection
, and ManagementObject
all implement IDisposable
. You should call Dispose()
or use "using
" to avoid leaking resources.
这篇关于什么API调用,我会用它来改变笔记本电脑(.NET)的亮度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!