views:

48

answers:

1

Hi all

How do I get my monitor's properties? I'm mostly interested in the manufacturer name and model type. I also don't want to get it from the registry. (Some PC's like my work PC has restricted access to the property key so I'd rather want to scan a system bus or something other than the reg.)

Any ideas? Thanks SoulBlade

+3  A: 

try using the Win32_DesktopMonitor WMI Class. this class have all the information wich you are looking.

check 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.
RRUZ