Delphi-Quellcode:
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Printers, StdCtrls, Registry, WinSpool; // einiges kann man entfernen...
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]));
end;
Beispiele:
Memo1:
ScanSoft PDF Create! : Ne00:
Samsung CLP-510N(
TCP) : Ne01:
Panasonic KX-P8415-LPT1 : LPT1:
Panasonic KX-P8415 (USB) : Ne02:
Panasonic KX-P8415 (LPT1) : LPT1:
Panasonic KX-P8415 (AXIS-200) : Ne03:
P-COLOR-AXIS-200 : Ne04:
Microsoft Office Document Image Writer : Ne05:
FreePDF XP : Ne06:
FinePrint : FPR5:
\\
http://192.168.1.201\CLP-510N : Ne07:
Active printer is : \\
http://192.168.1.201\CLP-510N
Port : Ne07: