Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Script to add network printers - troubleshooting

socketboy (TechnicalUser) (OP)
2 Nov 11 17:10
Hello, I found this thread, and am trying to get this script to work.
http://www.tek-tips.com/viewthread.cfm?qid=973606#post

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.")
Geates (Programmer)
2 Nov 11 17:42
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
 

socketboy (TechnicalUser) (OP)
3 Nov 11 9:44
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.

 
Geates (Programmer)
3 Nov 11 10:14
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""    /f C:C:\HP LJ8150\HP8150c.INF   /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
 

socketboy (TechnicalUser) (OP)
3 Nov 11 10:37
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
socketboy (TechnicalUser) (OP)
3 Nov 11 10:39
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
Geates (Programmer)
3 Nov 11 16:54
double quotes?

CODE

oshell.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b ""HP LJ 8150 Library Desk"" /f ""C:\HP LJ8150\HP8150c.INF"" /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
 

socketboy (TechnicalUser) (OP)
3 Nov 11 17:50
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  
Geates (Programmer)
4 Nov 11 8:46
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
 

socketboy (TechnicalUser) (OP)
4 Nov 11 9:23
Great, thank you for all your help/advice Geates :)  

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close