List all physical printers using WMI query in Inno Setup

倖福魔咒の 提交于 2019-12-04 20:02:30

You have to iterate the result set:

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;

The code requires Unicode version of Inno Setup for a better Variant support.


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

Note how the Win32_NetworkAdapterConfiguration is iterated there.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!