Solved

Printer setup script / utility for "local printer" on TCP/IP port in Windows (non-domain) - remove conflicts then add port and printer

Posted on 2010-11-28
11
1,651 Views
Last Modified: 2012-06-27
Does anyone know of a utility (or does anyone know how to write a script) that can work on Windows 7 and Windows XP (it could be two separate utilities/scripts) and can:

1) Remove any TCP/IP printer ports on a given IP address
2) Add a new TCP/IP printer port on that IP address
3) Add the printer on that port and install the driver from a network path to a .inf file

You can assume the script will be run as administrator.

If it relies on a utility, ideally it would be one that comes installed with Windows, but if not that might still be fine.

This is not being used on a Windows domain, so unfortunately some potentially easy solutions along those lines aren't available.
0
Comment
Question by:g9194
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 6

Accepted Solution

by:
RootsMan earned 500 total points
ID: 34229951
For Windows 7, the location of the Printing Administration Scripts are in C:\Windows\System32\Printing_Admin_Scripts\en-US\.

You can use prnport.vbs to add a Standard TCP/IP Port:

cscript //NoLogo prnport.vbs -a -r IP_%1 -h %1 -me -y public -o raw -n 9100

Open in new window

- Where %1 is the IP address of the printer.


You can use prnmngr.vbs to add the printer driver:

cscript //NoLogo prnmngr.vbs -a -p %1 -m %2 -r "IP_%3"

Open in new window


Where:
- %1 is the Name of the Printer
- %2 is Name of the Printer Driver
- %3 the is IP Address of the Printer

0
 

Author Comment

by:g9194
ID: 34230395
Thanks, I'll plan to give that a try later.  Does it also take care of bullet #1 (removing any existing ports on that IP [and I assume by implication any printers on those ports])?
0
 
LVL 6

Assisted Solution

by:RootsMan
RootsMan earned 500 total points
ID: 34230514
prnport.vbs will also allow you to remove a port with the -d parameter.

0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:g9194
ID: 34236104
It looks like -d will allow deletion of a port, but when I tried it, it gave me an error.  I'm wondering if the printer needs to be removed first so it's not using that port.  If that's it, how can I have it accomplish that - is there something that will automatically delete the port and printer on a certain IP?

cscript //NoLogo delete_port.vbs -d -r "192.168.1.200"

Unable to delete port Error 0x80041001 Generic failure
Operation DeleteInstance
Provider Win32 Provider
Description The requested resource is in use.
0
 
LVL 6

Expert Comment

by:RootsMan
ID: 34236507
Yes. Try deleting the printer first and then deleting the port that printer was using.

cscript //NoLogo prnmngr.vbs -d -p "Name of the Printer to Delete"

Open in new window

0
 

Author Comment

by:g9194
ID: 34241926
Hmm... the script won't necessarily know the name of the printer - it needs to be able to delete it by IP address.  Should I close this question and give partial points and then open a separate question?
0
 
LVL 6

Expert Comment

by:RootsMan
ID: 34244159
Do you really need to delete the TCP/IP port?

The name of the printer is required in order to target it for management.

To delete the TCP/IP port you'll have to free up the port by, 1. changing the port that the printer is using to something else:

cscript //NoLogo prncnfg.vbs -t -p "Printer Name" -r "IP_192.168.1.101"

Open in new window


or 2. deleting the printer:
cscript //NoLogo prnmngr -d -p "printer name"

Open in new window



BTW, once you add a new printer, if you want to make it the "Default" you can use the following code in your .vbs script:

Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "HP LaserJet 5Si"

Open in new window



0
 

Author Comment

by:g9194
ID: 34245383
I think I do need to delete it to prevent a conflict.

If you don't know how to delete a printer and port given ONLY an IP address, that's ok - I might be able to take the help you gave me so far and then ask that as a separate question.

Thanks!
0
 
LVL 6

Assisted Solution

by:RootsMan
RootsMan earned 500 total points
ID: 34247782
The list generated by cscript prnmngr.vbs -l will show the Printer name and Port name. Maybe you can parse that list to pull out the name, or use that info when you ask a separate question.

Just curious of where do you think the conflict would be?

0
 

Author Comment

by:g9194
ID: 34254812
Ah, maybe there isn't one.  I guess I just assumed you couldn't have two on the same port.  I'll go ahead and accept your answers.  Thanks for the help!
0
 

Author Closing Comment

by:g9194
ID: 34254816
I felt like there could have been better reading done so that so much back and forth wasn't required, but overall I was happy with the help that was provided.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question