I am trying to get EnumPrinters to return all printers on a domain (or a local network).
var
pcbNeeded, pcReturned: DWORD;
Buffer, PrinterInfo: PChar;
I: integer;
begin
EnumPrinters(PRINTER_ENUM_REMOTE or PRINTER_ENUM_SHARED, nil, 1, nil, 0, pcbNeeded, pcReturned);
GetMem(Buffer, pcbNeeded);
try
EnumPrinters(PRINTER_ENUM_REMOTE or PRINTER_ENUM_SHARED, nil, 1, PByte(Buffer), pcbNeeded, pcbNeeded, pcReturned);
PrinterInfo := Buffer;
for I := 0 to pcReturned -1 do
with PPrinterInfo1(PrinterInfo)^ do
begin
ListBox1.Items.Add(StrPas(pName));
Inc(PrinterInfo, SizeOf(TPrinterInfo1));
end;
finally
FreeMem(Buffer);
end;
end;
As far as the documentation goes, EnumPrinters function (Winspool.h) - Win32 apps | Microsoft Learn, this should work. But it returns nothing. If I replace PRINTER_ENUM_REMOTE with PRINTER_ENUM_LOCAL I get SOME of the local printers.
Anyone tried this successfully before?