• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 600
  • Last Modified:

How can I write a script to add a local printer (possibly multiple local printers) to a users PC.

I'm deploying multiple Brother MFC-7840 multifunctional devices at various sites.  They are to be set up locally using a static IP on each device.  Any given end-user could potentially use any of the printers since the users will roam from site to site.  I'm looking for the easiest method to install the driver and install the printers on each machine.  I'm hoping I can "push" the drivers out via Altris, then run a script to install the printers.
0
LotsOfHats
Asked:
LotsOfHats
  • 6
  • 4
1 Solution
 
LotsOfHatsAuthor Commented:
This is close, but I'm wanting a script to add local printers...I'm hoping I can push out the same drivers to all the machines...Then make a sharepoint site with a seperate script for each local printer, then the user can simply execute the script corresponding to the location they are at (the script will contain the static IP address)
0
 
activephotoCommented:
You can for example use rundll32 printui.dll,PrintUIEntry so take a look at this document from Microsoft
http://download.microsoft.com/download/8/2/c/82cffcfa-56f6-4fc3-bfa5-80cd84793871/PrintUIUsersGuide.doc
Of course you need to take care of adding the Standard TCP/IP printer ports as well.
I do have one question, why do you want to manage all printers locally on all clients, even cross sites? You will have a huge administration task to handle all those,
you should consider to use a print server on each site at least and the users mapping to those printers.
/ Mikael
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LotsOfHatsAuthor Commented:
Here is what I am using to created the TCP/IP port.
"Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = 192.168.1.2
objNewPort.Protocol = 1
objNewPort.HostAddress = 192.168.1.2
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_"

After this step I am lost, I looked at the documentation you sent, but it looks like it is just for adding printers with a print server....Also, just to give a little background, I am very new to scripting, in fact  this is the first script I've ever actually worked on....So, please be very specific when replying (borderline elementary)...And to answer your question, these printers are going to be in dirty communication shacks and will not be used all that often.
0
 
LotsOfHatsAuthor Commented:
I think my problem is using a driver that is not part of .cab file.... After I created the port, this is what i am trying to execute...

net stop spooler
net start spooler

start /wait rundll32 printui.dll,PrintUIEntry /if /b "<PRINT-cresson>" /f "%Drivers%\brotherprinter\usa\BRPR784W.inf" /r "IP_172.20.150.146" /m "MFC-7840W" /z /u
0
 
activephotoCommented:
Do you get any error message when you run the above rundll32 command string? (I assume that the drivers are copied to the computer you are referring the /f parameter)
there is another way of adding printers, drivers, ports etc, and that is by using some built-in VB-scripts
Add, Delete and list print drivers
prndrvr.vbs (see ref ... http://technet.microsoft.com/en-us/library/bb490972.aspx)
Add, Delete and list printers and printer connections
prnmngr.vbs (see ref ...http://technet.microsoft.com/en-us/library/bb490974.aspx)
Add, Delete and list Printer ports
prnport.vbs (see ref ... http://technet.microsoft.com/en-us/library/bb490975.aspx)
there are quite good examples in the references above.
but I am interested to know if you got any error messages from the rundll32 command you was running.
/ Mikael
0
 
LotsOfHatsAuthor Commented:
Here is where I am at now....I could not get the rundll32 command to install the drivers from a share on my PC, but the command worked perfectly when using drivers that where already included in Windows.  I talked to brother support and they said that the HP LaserJet II P Driver was compatable with thier device, and they were correct, the printer works great using that driver.

So, with that being said, I can achieve what I am wanting in two files (1) VBS and (1) rundll32 command...I'll attach both for you to view.  Any ideas on how to combine in to one or have one automatically cal lthe other?  
PortIP = "172.17.128.113"
PortName = "IP_" & PortIP
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
''''''''''''''''''''''''''
' create ip-printer-port
''''''''''''''''''''''''''
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
 
objNewPort.Name = PortName
objNewPort.Protocol = 1
objNewPort.HostAddress = PortIP
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = True
objNewPort.Put_
 
' wsh.echo "port created"
 
 
 
HERE IS THE RUNDLL32 FILE:
 
net stop spooler
net start spooler
 
sleep 10
 
set DRIVER=HP LaserJet IIP
 
rundll32 printui.dll,PrintUIEntry /if /b "PRINT-SWIFT" /f "%windir%\inf\ntprint.inf" /r "IP_172.17.128.113" /m "%DRIVER%" /n "Brother MFC-7840W" /z /u

Open in new window

0
 
activephotoCommented:
you can start the rundll32 from the vb script by including the following code (hope I got all the " correct in the objshell.Run
regarding the problem installing from a share (if you mean e.g. \\computer\share)  could be that some drivers cannot be installed when using an UNC path.
look at the code below and see if thats working for you, here is also a link for Wscript.Shell, it is for windows 2000 but I do believe its the same syntax.
http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_pkoy.mspx?mfr=true
Good luck
/ Mikael

Set objShell = CreateObject("Wscript.Shell")
objShell.Run "rundll32 printui.dll,PrintUIEntry /if /b ""PRINT-SWIFT"" /f ""%windir%\inf\ntprint.inf"" /r ""IP_172.17.128.113"" /m ""%DRIVER%"" /n ""Brother MFC-7840W"" /z /u
 

Open in new window

0
 
LotsOfHatsAuthor Commented:
I've enclosed what I've added and my script is not working
PortIP = "172.17.128.113"
PortName = "IP_" & PortIP
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
''''''''''''''''''''''''''
' create ip-printer-port
''''''''''''''''''''''''''
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
 
objNewPort.Name = PortName
objNewPort.Protocol = 1
objNewPort.HostAddress = PortIP
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = True
objNewPort.Put_
 
' wsh.echo "port created"
 
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "rundll32 printui.dll,PrintUIEntry /if /b "PRINT-SWIFT" /f "%windir%\inf\ntprint.inf" /r "IP_172.17.128.113" /m "HP LaserJet IIP" /n "Brother MFC-7840W" /z /u"
  

Open in new window

0
 
activephotoCommented:
There is a problem with the quotation marks (") in the objShell.Run row.
You are including the whole command in within "" and inside that you have quotation marks for e.g driver name etc. those should have double quotation marks ("")
see example below
/ Mikael

objShell.Run "rundll32 printui.dll,PrintUIEntry /if /b ""PRINT-SWIFT"" /f ""%windir%\inf\ntprint.inf"" /r ""IP_172.17.128.113"" /m ""HP LaserJet IIP"" /n ""Brother MFC-7840W"" /z /u"

Open in new window

0
 
LotsOfHatsAuthor Commented:
Thanks for your help....Here is my working script

PortIP = "xxx.xxx.xxx.xxx"
PortName = "IP_" & PortIP

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

''''''''''''''''''''''''''
' create ip-printer-port
''''''''''''''''''''''''''
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = PortName
objNewPort.Protocol = 1
objNewPort.HostAddress = PortIP
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = True
objNewPort.Put_

' wsh.echo "port created"

Set objShell = CreateObject("Wscript.Shell")

objShell.Run "cmd /c rundll32 printui.dll,PrintUIEntry /if /b ""PRINT-TEST"" /f ""%windir%\inf\ntprint.inf"" /r ""IP_xxx.xxx.xxx.xx"" /m ""HP LaserJet IIP"" /z /u"
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now