gpt4 book ai didi

windows - 检测设备(打印机、扫描仪、鼠标等)是否不工作

转载 作者:可可西里 更新时间:2023-11-01 11:18:38 25 4
gpt4 key购买 nike

如果打印机有问题,Windows 的设备管理器会在有问题的打印机旁边显示一个特殊图标。

我正在使用 Delphi XE2,我想知道如何以编程方式检测 Windows XP 或更高版本的此类信息,即。

function DetectDriversProblems() : TStringList;
begin
// Scan Computer or query Windows to know if a driver has issues and
// return list of faulty hardware (if any)
end;

最佳答案

您可以使用 Win32_PnPEntity WMI 类和 ConfigManagerErrorCode 属性。

{$APPTYPE CONSOLE}

uses
SysUtils,
ActiveX,
ComObj,
Variants;

Procedure ListDevicesConfigError;
const
wbemFlagForwardOnly = $00000020;
var
FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
begin;
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\cimv2', '', '');
FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode <> 0','WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
Writeln(Format('Class GUID %s',[String(FWbemObject.ClassGUID)]));
Writeln(Format('Description %s',[String(FWbemObject.Description)]));
Writeln(Format('Device ID %s',[String(FWbemObject.DeviceID)]));
Writeln(Format('Manufacturer %s',[String(FWbemObject.Manufacturer)]));
Writeln(Format('Name %s',[String(FWbemObject.Name)]));
Writeln(Format('PNP Device ID %s',[String(FWbemObject.PNPDeviceID)]));
Writeln('');
FWbemObject:=Unassigned;
end;
end;

begin
try
CoInitialize(nil);
try
ListDevicesConfigError;
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');
Readln;
end.

关于windows - 检测设备(打印机、扫描仪、鼠标等)是否不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24067988/

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