Skip navigation

JSI Tip 1410. How can I automate DOS default network printer assignment in a logon script?

To use a network printer in a DOS program, you must issue a:

NET USE LPTx: \\ComputerName\PrinterShare.

In tip 0672, we learned that the default printer information is located at:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device

Using REGFree, we can add either of the following to a logon script:

for /f "Tokens=1-5 Delims=,: " %%i in ('reg -listvalue "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"') do set prt=%%j&set port=%%l
net use %port%: %prt%

for /f "Tokens=2 Delims=, " %%i in ('reg -listvalue "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"') do set prt=%%i
net use LPT1: %prt%

Hide 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.