PDA

Ver la Versión Completa : Determinar puerto de impresión


MAXIUM
11-02-2008, 17:06:06
Hola, quisiera saber que tipo de puerto usa la impresora determinada. Uso el siguiente código pero al mostara el tipo de puerto me aparece en blanco.


Uses Printers;

Type
TPrinterDevice = Class Driver, Device, Port: String;

TForm1.Button1Click(Sender:TObject);
Begin
// Para obtener el nombre de la impresora.
Label1.Caption:= TPrinterDevice(Printer.Printers.Objects[Printer.PrinterIndex].Device;

// Para obtener el tipo de puerto.
Label2.Caption:= TPrinterDevice(Printer.Printers.Objects[Printer.PrinterIndex].Port;
End;

cHackAll
12-02-2008, 03:41:11
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;

MAXIUM
12-02-2008, 15:38:44
Muchisimas gracias, funciona de maravillas.