Link to home
Start Free TrialLog in
Avatar of LotsOfHats
LotsOfHats

asked on

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.
Avatar of Dhiraj Mutha
Dhiraj Mutha
Flag of United States of America image

Avatar of LotsOfHats
LotsOfHats

ASKER

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

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

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

ASKER CERTIFIED SOLUTION
Avatar of Mikael Jansson
Mikael Jansson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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"