Statt LPT1: schreibst Du die Netzwerkbezeichnung des Druckers - z.B. Ne00:
Delphi-Quellcode:
Function Get_Printerport(Printername: string): string;
var
Reg: TRegistry;
p: Integer;
begin
Reg := TRegistry.Create;
with Reg do
begin
RootKey := HKEY_CURRENT_USER;
if OpenKey('\Software\Microsoft\Windows NT\CurrentVersion\Devices\', True) then
begin
if ValueExists(Printername) then
begin // The reg Key value may look like "winspool,LPT1:"
Result := ReadString(Printername);
p := Pos(',', Result);
Result := Copy(Result, p + 1,Length(Result) - p);
end;
end;
CloseKey;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
var i:integer;
begin
Memo1.Clear;
ListBox1.Items := Printer.Printers;
for i := 0 to ListBox1.Count - 1 do
begin
Memo1.Lines.Add(ListBox1.Items.Strings[i]+' : '+ Get_Printerport(ListBox1.Items.Strings[i]));
end;
Memo1.Lines.Add('Active printer is : '+ Printer.Printers[Printer.PrinterIndex]);
Memo1.Lines.Add('Port : '+ Get_Printerport(Printer.Printers[Printer.PrinterIndex]));
Label1.Caption := '';
end;