在Inno Setup中使用WMI查询列出所有物理打印机 [英] List all physical printers using WMI query in Inno Setup

查看:135
本文介绍了在Inno Setup中使用WMI查询列出所有物理打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据但是得到:发送到OneNote 16".

But just get: "Send To 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;

推荐答案

您必须迭代结果集:

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;

该代码需要Unicode版本的Inno Setup,以提供更好的Variant支持.

实际上,您可以在同一问题中看到此代码,您从以下位置获取了WbemQuery:
是否可以通过Inno Setup读取系统信息

Actually, you can see this code in the same question, where you took the WbemQuery from:
Is there a way to read the system's information in Inno Setup

请注意Win32_NetworkAdapterConfiguration在此处如何迭代.

Note how the Win32_NetworkAdapterConfiguration is iterated there.

这篇关于在Inno Setup中使用WMI查询列出所有物理打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆