我正在尝试根据Query available RAM in Inno Setup的答案获取与Windows连接的物理打印机名称列表。
但是得到:“发送到OneNote 16”。
这是我的问题:
Query := 'SELECT Name FROM Win32_Printer';
Printer := WbemQuery(WbemServices, Query);
if not VarIsNull(Printer) then
begin
Log(Format('Printers=%s', [Printer.Name]));
end;
答案 0 :(得分:1)
您必须迭代结果集:
var
Query: string;
WbemLocator, WbemServices, WbemObjectSet: Variant;
Printer: Variant;
I: Integer;
begin
WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
WbemServices := WbemLocator.ConnectServer('.', 'root\CIMV2');
Query := 'SELECT Name FROM Win32_Printer';
WbemObjectSet := WbemServices.ExecQuery(Query);
if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then
begin
for I := 0 to WbemObjectSet.Count - 1 do
begin
Printer := WbemObjectSet.ItemIndex(I);
if not VarIsNull(Printer) then
begin
Log(Printer.Name);
end;
end;
end;
end;
该代码需要better Variant
support的Inno Setup的Unicode版本。
实际上,您可以在同一个问题中看到此代码,您可以从中获取WbemQuery
:
Is there a way to read the system's information in Inno Setup
注意Win32_NetworkAdapterConfiguration
是如何迭代的。