gpt4 book ai didi

德尔福7 : Get attached monitor properties

转载 作者:行者123 更新时间:2023-12-03 15:29:47 25 4
gpt4 key购买 nike

如何获取显示器的属性?我最感兴趣的是制造商名称和型号类型。我也不想从注册表中获取它。 (有些电脑(例如我的工作电脑)对属性 key 的访问受到限制,因此我宁愿扫描系统总线或除注册表之外的其他内容。)

有什么想法吗?谢谢灵魂之刃

最佳答案

尝试使用Win32_DesktopMonitor WMI 类。这个类(class)有您正在寻找的所有信息。

检查此示例代码。

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.

关于德尔福7 : Get attached monitor properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3904619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com