Delphi7: get the properties of a connected monitor

How to get monitor properties? I am mainly interested in the name of the manufacturer and the type of model. I also do not want to get it from the registry. (Some PCs, like my working PC, have restricted access to the property key, so I would prefer to scan the system bus or something other than reg.)

Any ideas? Thanks SoulBlade

+4
source share
1 answer

try using the Win32_DesktopMonitor WMI class. this class has all the information you are looking for.

check out this sample code.

 program GetWMI_MonitorInfo; {$APPTYPE CONSOLE} uses SysUtils, ActiveX, ComObj, Variants; function VarStrNull(VarStr:OleVariant):string;//dummy function to handle null variants begin Result:=''; if not VarIsNull(VarStr) then Result:=VarToStr(VarStr); end; procedure GetMonitorInfo; var objWMIService : OLEVariant; colItems : OLEVariant; colItem : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; function GetWMIObject(const objectName: String): IDispatch; var chEaten: Integer; BindCtx: IBindCtx; Moniker: IMoniker; begin OleCheck(CreateBindCtx(0, bindCtx)); OleCheck(MkParseDisplayName(BindCtx, StringToOleStr(objectName), chEaten, Moniker)); OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, Result)); end; begin objWMIService := GetWMIObject('winmgmts:\\localhost\root\CIMV2'); colItems := objWMIService.ExecQuery('SELECT * FROM Win32_DesktopMonitor','WQL',0); oEnum := IUnknown(colItems._NewEnum) as IEnumVariant; if oEnum.Next(1, colItem, iValue) = 0 then begin Writeln('Caption '+VarStrNull(colItem.Caption)); Writeln('Description '+VarStrNull(colItem.Description)); Writeln('Device ID '+VarStrNull(colItem.DeviceID)); Writeln('Manufacturer '+VarStrNull(colItem.MonitorManufacturer));//Manufacter Writeln('Type '+VarStrNull(colItem.MonitorType));//Model end; end; begin try CoInitialize(nil); try GetMonitorInfo; Readln; finally CoUninitialize; end; except on E:Exception do Begin Writeln(E.Classname, ': ', E.Message); Readln; End; end; end. 
+4
source

All Articles