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.
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/downlo ad/8/2/c/8 2cffcfa-56 f6-4fc3-bf a5-80cd847 93871/Prin tUIUsersGu ide.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
http://download.microsoft.
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
ASKER
Here is what I am using to created the TCP/IP port.
"Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort") .SpawnInst ance_
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.
"Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort")
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.
ASKER
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\BRPR78 4W.inf" /r "IP_172.20.150.146" /m "MFC-7840W" /z /u
net stop spooler
net start spooler
start /wait rundll32 printui.dll,PrintUIEntry /if /b "<PRINT-cresson>" /f "%Drivers%\brotherprinter\
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.c om/en-us/l ibrary/bb4 90972.aspx )
Add, Delete and list printers and printer connections
prnmngr.vbs (see ref ...http://technet.microsoft.com /en-us/lib rary/bb490 974.aspx)
Add, Delete and list Printer ports
prnport.vbs (see ref ... http://technet.microsoft.c om/en-us/l ibrary/bb4 90975.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
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.c
Add, Delete and list printers and printer connections
prnmngr.vbs (see ref ...http://technet.microsoft.com
Add, Delete and list Printer ports
prnport.vbs (see ref ... http://technet.microsoft.c
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
ASKER
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?
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
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/t echnet/scr iptcenter/ guide/sas_ wsh_pkoy.m spx?mfr=tr ue
Good luck
/ Mikael
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/t
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
ASKER
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"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help....Here is my working script
PortIP = "xxx.xxx.xxx.xxx"
PortName = "IP_" & PortIP
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
''''''''''''''''''''''''''
' create ip-printer-port
''''''''''''''''''''''''''
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort") .SpawnInst ance_
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.Shel l")
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"
PortIP = "xxx.xxx.xxx.xxx"
PortName = "IP_" & PortIP
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
''''''''''''''''''''''''''
' create ip-printer-port
''''''''''''''''''''''''''
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort")
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.Shel
objShell.Run "cmd /c rundll32 printui.dll,PrintUIEntry /if /b ""PRINT-TEST"" /f ""%windir%\inf\ntprint.inf
https://www.experts-exchange.com/questions/23964083/Configuration-of-Printers.html