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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script or Batch file to Install Printers

Status
Not open for further replies.

yellowartist

IS-IT--Management
Aug 5, 2007
19
0
0
US
I am wanting to create a script or a batch file that I can post on a intranet site that I can direct users to for printer installs.

We like to have the printer installed as a local printer, with a tcp/ip port (this resolves both by the IP address or the name of the printer). Here is the code I have wrote

Code:
StrPrinterName = ("WCP3516_PS")
StrPrintinfloc = "\\Server\installs\drivers\Printer\Xerox\Xerox_Work_Center\Pro_35_45_55\WXP\ps\Xrw55ps.inf"
StrTCPIP = "xxx.xxx.xxx.xxx"
StrPortName = ("WCP3516")

set objShell = CreateObject("Wscript.Shell")

'Installs Printer
Objshell.Run "%comspec% /c " & "rundll32 printui.dll,PrintUIEntry /if /b" & StrPrinterName & " /f" & StrPrinterinflocation & " /r" & StrPortName & " /m" & StrPrintinfloc & ",,True"

Everytime I run it I get the following error:

The box says "Printers"
Error Msg: "The arguments are invalid"

I have tried this on multiple computers.
Verified the path of the inf files and made sure I had access to it with the credentials I was logged on with.
Made sure I could ping the printer both by name or ip. I also just tried it with a batch file as follows.

Code:
rundll32 printui.dll,PrintUIEntry /if /b "WCP3516" /f
\\server\share\inf\ntprint.inf /r "IP_xxx.xxx.xxx.xxx" /m "printer driver"

Any help is appreciated.
Thanks.
 
Ok I got it to work... here is what I've done.
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewPort = objWMIService.Get _
    ("Win32_TCPIPPrinterPort").SpawnInstance_

objNewPort.Name = "IP_xxx.xxx.xxx.xxx"
objNewPort.Protocol = 1
objNewPort.HostAddress = "xxx.xxx.xxx.xxx"
objNewPort.PortNumber = "9999"
objNewPort.SNMPEnabled = False
objNewPort.Put_


Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_

objPrinter.DriverName = "Xerox WorkCentre Pro 35 PS"
objPrinter.PortName   = "IP_xxx.xxx.xxx.xxx"
objPrinter.DeviceID   = "WCP3516_PS"
objPrinter.Network = False
objPrinter.Shared = False
objPrinter.Put_
 
Could you modify this code to use a custom printer driver?

I would very much appreciate the help if at all possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top