...retrieve the Port of a given Printer (W2K, XP)?

Author: jahuer1

Category: Printing

// Mit bestem Dank an "Blitz" für die Grundidee!

uses
  
Registry;

//...

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
        
// Im reg Key steht so etwas wie   "winspool,LPT1:"
        // 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;

 

printed from
www.swissdelphicenter.ch
developers knowledge base