none
Adding 'Local' Printer Port Via Script RRS feed

  • Question

  • Hello All,

    I’m having problems installing a [b]Local[/b] printer port via script. For years I’ve used scripts like below.
    Creates Port:

    cscript %windir%\system32\printing_admin_scripts\en-us\prnport.vbs -a -r "IP_1.1.1.1" -h "1.1.1.1" -o raw

    Installs Printer to above specified port:

    rundll32.exe printui.dll,PrintUIEntry /if /b "Printer Name" /f “Printer Driver Path\file.inf" /r "IP_1.1.1.1" /m "Printer XXX"

    I’ve used this successfully for decades, it keeps everything exactly the same and saves tons of time.

    My problem:
    I need to make a nul printer, which I can do manually no problem, but I’ll be damned if I can figure out how to make a local nul port with a script. 

    This works fine to install the printer if I manually make the Nul Printer through the gui:

    rundll32.exe printui.dll,PrintUIEntry /if /b "NullPrinter" /f "%windir%\inf\ntprint.inf" /r "nul:" /m "Printer XXX"

    but I would rather not have to create the NUL: port manually on 300 systems if possible.

    The problem I’m sure is the” –h” switch,  which tells it there is an IP address. If I run it like:

    cscript %windir%\system32\printing_admin_scripts\en-us\prnport.vbs -a -r "nul:" -h "nul:" -o raw

    It does create the port, but it creates it as a Standard TCP/IP port which of course is not what I need and does not function as a NUL port. I’ve tried every variation of syntax I can come up with and none seem to work. I’ve looked for the last couple of hours on the internet and everything always references creating an IP port not a Local Port like NUL.

    Any help would be great.
    Thanks




    • Edited by EricMcC Thursday, November 14, 2019 7:35 PM
    Thursday, November 14, 2019 7:33 PM

All replies

  • What problem does this solve? Why not map network printers using GPOs?

    Aside from this, the prnport.vbs script is a built-in Windows tool. We didn't write it and don't have any special insight on how to make it do what you want. (This is what causes me to ask what's provoking the question in the first place.)


    -- Bill Stewart [Bill_Stewart]

    Thursday, November 14, 2019 8:55 PM
    Moderator
  • What?

    What difference does it make if you didn't write it, I'm just asking if anybody knows how to create a local nul port from a command line, if the prnport.vbs script won't do it is there some other way. You seem to hint at GPO, I'll have to look into it.

    I need to setup 300 systems with a Nul printer so I can force jobs that print automatically and waste paper to dump to a nul printer instead.


    • Edited by EricMcC Thursday, November 14, 2019 9:09 PM
    Thursday, November 14, 2019 9:08 PM
  • What do you mean by "jobs that print automatically"?


    -- Bill Stewart [Bill_Stewart]

    Thursday, November 14, 2019 9:15 PM
    Moderator
  • I'm not sure why that's relevant but, our Business Solution software prints 2 copies of invoices automatically and as of now, that can't be changed and isn't going to change for some time.

    However, I can define the Crystal report that creates the invoice (that prints automatically) to dump to a specific printer. If I create a Nul printer I'll be set.

    Thursday, November 14, 2019 9:25 PM
  • I don't see a way to create a Nul printer port in the GPO either.
    Thursday, November 14, 2019 9:26 PM
  • Sounds like an issue to be addressed in your software, but in any case you could also install a PDF printer (or similar) and just delete the spooled files you don't want. But in any case I'm not really sure your question is a good fit for this forum.

    -- Bill Stewart [Bill_Stewart]

    Thursday, November 14, 2019 10:38 PM
    Moderator
  • As noted, there is no need to script this. Just create a printer of any kind an d set it to "paused". Delete the spooled files each day or as needed.


    \_(ツ)_/

    Thursday, November 14, 2019 11:49 PM
  • I just can't believe how little information there is on creating a Nul printer. You can't do it with a GPO, or PowerShell, (in Windows 7) and the built in Windows VBS scripts won't create a local port.

    Here's how to do it.

    Add this to the registry:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports]
    "nul:"=""
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Ports]
    "nul:"=""

    Restart the Print Spooler service

    And run this command:

    rundll32.exe printui.dll,PrintUIEntry /if /b "NullPrinter" /f "%windir%\inf\ntprint.inf" /r "nul:" /m "Generic / Text Only"

    It'll take about 30 seconds for it to pop up in the printers, but... it will create a printer named NullPrinter that prints to a nul: localport. I haven't tested it yet on Windows 10 but it works fine on 7, (32 and 64) which at the moment is what I need.

    All of my other printer scripts work just fine on windows 10 so I suspect this one will too, but I may need to adjust the print driver if "Generic / Text Only" doesn't exist in Windows 10, as well as the reg settings if they are different. I'll update when I get a chance.


    • Edited by EricMcC Friday, November 15, 2019 1:27 PM
    Friday, November 15, 2019 1:26 PM
  • None of this has anything to do with scripting.

    Also it is easy to crate pronter ports in PowerShell with one command - Add-PrinterPort. In VBS you can create ports with the WMI Win32_PronterPort class.

    You can also just print to the nul device:

     print test.txt /d:nul:


    \_(ツ)_/

    Friday, November 15, 2019 1:44 PM
  • sorry for posting it in the wrong place:

    Add-PrinterPort does not exist in Windows 7 PowerShell.

    It doesn't matter anyway, I figured it out and have what I need. 

    Friday, November 15, 2019 2:22 PM
  • In windows 7 (which is no longer in support (jan 2010) can use "Win32_TCPIPPrinterPort " to create a printer port.

    There are script in the gallery that will create ports and printers in Win7.


    \_(ツ)_/

    Friday, November 15, 2019 2:57 PM