uses WinSpool;
procedure TForm1.Button1Click(Sender: TObject);
var
Size, Count, Index: Cardinal;
Items: array [0..2047] of TPrinterInfo5;
Default: array [0..255] of Char;
begin
EnumPrinters(PRINTER_ENUM_LOCAL + PRINTER_ENUM_CONNECTIONS, nil, 5, @Items, SizeOf(Items), Size, Count);
GetProfileString('windows', 'device', '', @Default, SizeOf(Default) - 1);
Index := 0; while not (Default[Index] in [#0, ',']) do Inc(Index);
Default[Index] := #0;
for Index := 0 to Count - 1 do
if not LongBool(lstrcmpi(@Default, Items[Index].pPrinterName)) then
MessageBox(Handle, Items[Index].pPortName, nil, 0);
end;