GetMonitorCapabilities function
Retrieves the configuration capabilities of a monitor. Call this function to find out which high-level monitor configuration functions are supported by the monitor.
Requirements: Minimum supported client: Windows Vista
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
WmiSetBrightness method of the WmiMonitorBrightnessMethods class
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
Delphi-Quellcode:
program SETBright;
{$APPTYPE CONSOLE}
uses
SysUtils,
ActiveX,
Variants,
ComObj;
var dark : Integer;
darkStr :
String;
procedure SetBrightness(Timeout : Integer; Brightness : Byte);
var
FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
begin;
FSWbemLocator := CreateOleObject('
WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer('
localhost', '
root\WMI', '
', '
');
FWbemObjectSet:= FWMIService.ExecQuery('
SELECT * FROM WmiMonitorBrightnessMethods Where Active=True','
WQL',$00000020);
oEnum := IUnknown(FWbemObjectSet._NewEnum)
as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0
do
begin
FWbemObject.WmiSetBrightness(Timeout, Brightness);
FWbemObject:=Unassigned;
end;
end;
begin
dark:=40;
//default
if ParamCount>0
then
begin
darkStr:= ParamStr(1);
dark:= StrToInt(darkStr);
end;
try
CoInitialize(
nil);
try
SetBrightness(5, dark);
finally
CoUninitialize;
end;
except
on E:EOleException
do
Writeln(Format('
EOleException %s %x', [E.
Message,E.ErrorCode]));
on E:
Exception do
Writeln(E.Classname, '
:', E.
Message);
end;
Writeln('
Press Enter to exit');
// delete it
Readln;
// delete it
end.
(*
Batch file: setbright.bat
setbright <0 - 100>
Example: setbright 40
*)
Crosspost:
http://www.entwickler-ecke.de/viewto...=680567#680567
Im Anhang: Source, EXE, Batchfiles