Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to add network printers - troubleshooting

Status
Not open for further replies.

socketboy

Technical User
Jul 30, 2004
7
US
Hello, I found this thread, and am trying to get this script to work.

When I run the script it just seems to jump straight through to the end and says "Printer installation complete." when nothing happens.

It looks like there is a menu to choose which printer to install, or install all of them. This would be perfect for my situation if I could get it to work, as is when I run the scrip that selection doesn't come up at all.

I am very new to this type of scripting, so I am probably making an easy mistake here.

I would be installing the printers with externally defined drivers, so I un-commented those lines and added my own printer names and IP addresses. I'm not sure where this is failing.

Any help would be much appreciated. Thanks

Please see my slightly modified code below:
Code:
'----------------------------------------------'
'----------------------------------------------'
'                                                '
'   Script to automate TCP/IP printer installs ' 
'       (Andrew Levine - 12/2004)              '
'                                                '
'----------------------------------------------'
'----------------------------------------------'


Set WSHNetwork = WScript.CreateObject("WScript.Network")
set shell = WScript.CreateObject( "WScript.Shell" )
CompName = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set objWMIService = GetObject("winmgmts:\\" & CompName & "\root\cimv2")
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_
Set oShell = WScript.CreateObject("WScript.shell")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_

sub createPort (name, ip)
    objNewPort.Name = name
    objNewPort.Protocol = 1
    objNewPort.HostAddress = ip
    objNewPort.SNMPEnabled = False
    objNewPort.Put_
end sub

sub addPrinter (driver, port, name)
    objPrinter.DriverName = driver
    objPrinter.PortName = port
    objPrinter.DeviceID = name
    objPrinter.Location = ""
    objPrinter.Network = True
    objPrinter.Shared = false
    objPrinter.ShareName = ""
    objPrinter.Put_ 
end sub

message = "Please choose a printer to install:" & vbCrLf & vbCrLf & "1: All Printers"  & vbCrLf &  "2: HP4200 North" & vbCrLf & "3: HP8150 Library Desk" & vbCrLf & "4: HP8500 Color PS" & vbCrLf& vbCrLf & vbCrLf & "Please enter 1-5 (leave blank to quit):"
title = "Install Printers - BCEHFP"

'------------------'
'Add printer ports:'
'------------------'
createPort "HPLJ8150_Library_Desk", "10.18.65.238"
createPort "CanoniR7095_Library_Copy", "10.18.66.249"
createPort "RICOHMPC300SR_Main_Office",   "10.18.65.247"

'----------------------------------------------'
'Install printers with drivers native to WinXP:'
'----------------------------------------------'
'                                                TCP/IP Port Name        Display Name
'                                                --------------------    -----------------
addPrinter "HP Color LaserJet 8500 PS",        "HP8500_Exec_color",     "HP8500 Color PS"
'addPrinter "HP LaserJet 4200 PS",                 "HP4200_BCEHFP_North",     "HP4200 North PS"
'addPrinter "HP LaserJet 4200 PCL 6",             "HP4200_BCEHFP_North",     "HP4200 North"

'-------------------------------------------------'    Display name
'Install printers with externally defined drivers:'    for printer              Driver location                    Port name                  Driver name in .inf file
'-------------------------------------------------'    -----------       ---------------------------------         ------------               -----------------------  
oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP LJ 8150 Library Desk""    /f C:C:\HP LJ8150\HP8150c.INF   /r ""HPLJ8150_Library_Desk"" /m ""HP LaserJet 8150 Series PCL6"""  ,,true
'oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP8150 South PS"" /f U:\instalxp\hp8150ps\HP8150PS.INF /r ""HP8150_BCEHFP_South"" /m ""HP LaserJet 8150 PS"""     ,,true



msgbox ("Printer installation complete.")
 
do these printers have network queues as the name suggests?

Code:
set objNetwork = WScript.CreateObject("WScript.Network")

'Add Network printers
objNetwork.AddWindowsPrinterConnection "\\server\printer_name"

'Set Default Printer
objNetwork.SetDefaultPrinter "\\server\printer_name"

-Geates


"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Nope, I need to be able to install by ip address, which it looks like the script should do, not sure why it fails, I get no errors on that front.

 
Nope, as in "They are not Network printer"?

server = ip

Code:
objNetwork.AddWindowsPrinterConnection "\\10.15.10.215\printer_name"

Anyway

Code:
oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP LJ 8150 Library Desk""    [red]/f C:C:\HP LJ8150\HP8150c.INF[/red]   /r ""HPLJ8150_Library_Desk"" /m ""HP LaserJet 8150 Series PCL6"""  ,,true

1. Missing quotes (surround the path with "")
2. Invalid path (c:c: isn't a drive)

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Sorry I think I misunderstood.
So yes, all of the printers are network printers, the one I'm trying to add in the script being 10.18.65.238.

So were you saying then I need to add a line like
Code:
objNetwork.AddWindowsPrinterConnection "\\10.15.10.215\printer_name"
to make it work?
What would be the printer name? Does it have to be the printer name as defined in the inf file?

Thanks for your help
 
Sorry forgot to include I did update the code to encase the path in quotes and got rid of that extra C:, no apparent change as far as it working.
Thanks
 
double quotes?

Code:
oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP LJ 8150 Library Desk"" /f [red]""C:\HP LJ8150\HP8150c.INF""[/red] /r ""HPLJ8150_Library_Desk"" /m ""HP LaserJet 8150 Series PCL6"""  ,,true

Do you have a server where printers are installed and shared out? I didn't think what I was saying all the way through. 10.15.10.215 is the IP of the printer, not the server. If you don't have a print server, the way I suggested will not work.

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
I am not sure actually about a print server. I am kind of a one man department right now, brand new to the role. I've been going around adding printers by their individual ip addresses. I am not aware of a print server at all, I think they are basically each their own mini print server.

Now I'm getting "(35, 5) SWbemObjectEx: Generic failure"

Is that referencing line 35, the objPrinter.Put_ ?
If so that's interesting, that's the same place another script failed that I had found online.

Is this due to not having a print server would you guess?

Thanks
 
It not due to not having a print server. Although the style in which that error is presented indicates it's not one from wscript (at least, I've never seen one like that). With that in mind, I would guess it is an error from within either RUNDLL32, PRINTUI.DLL, or the PrintUIEntry routine. If so, this would further suggest that the error originates from the data that defines the printer. Maybe the IP or printer driver.

If you're a one man department then the business is small enough to not constitute a print server. However, having on means central control over all printer and simple installations on client pc! I would strongly recommend researching it. If not for implementation, then for knowledge. It will certainly help a one man operation :).

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Great, thank you for all your help/advice Geates :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top