Skip navigation

How can I map the default printer to LPT1 from the command line?

A. Reader Daniel Wolf sent in the following Kixtart script that maps the current user's default printer to LPT1 (assuming the default printer is a network printer). To run the script, go to the command line and type

  kix32.exe printer.scr  
Kixtart is part of the Windows 2000 Server Resource Kit, Win2K Pro Resource Kit, Windows NT 4.0 Server Resource Kit, and NT 4.0 Workstation Resource Kit.

  --- printer.scr start (Kix Script) ---

   ; read Default Printer Server and Sharename from Windows Registry
   ; and map to LPT1 (Windows 2000 and Windows NT only; not tested on
   ; Windows XP)

   ; by Daniel Wolf
   ; [email protected]

   $Printer = READVALUE("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device");

   $Index = 1

   WHILE $Index < LEN($Printer)

   $Testchar = SUBSTR($Printer, $Index, 1)
   IF $Testchar = ','
           $Cutat = $Index - 1
           $Index = LEN($Printer)
   ENDIF

   $Index = $Index + 1

   LOOP

   $Printer = SUBSTR($Printer, 1, $Cutat)
   $Checklocal = SUBSTR($Printer, 1, 2)

   ? "Default Printer: $Printer"

   ; only map if Default Printer is Network Printer
   IF $Checklocal = "\\"
           ? "Removing existing LPT1 mapping ..."
           USE LPT1 /D
           USE LPT1 $Printer
                   IF @ERROR
                           BEEP
                           ? "Error @ERROR mapping $Printer to LPT1"
                   ELSE
                           ? "Done. $Printer mapped to LPT1"
                   ENDIF
   ELSE
           ? "ABORT. Default Printer is not a network printer!"
   ENDIF

   --- printer.scr end --- 
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish