Adding a network printer using VB script
The following script doesn't seem to be working. I am unable to read the error messages because the command prompt windows is disappearing to quickly. Where have I gone wrong? Here is my script - PrnName = "4009k Ricoh C4000 Fax" PrnLocation = "4009k" PrnComment = "Test printer script" PrnDrv = "LAN-Fax M8" DrvPath = "C:\z51052en\DISK1\" InfPath = DrvPath & "\PRINTER.inf" PortIP = "172.22.12.130" PortName = "IP_172.22.12.130" & 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 = False objNewPort.Put_ ' wsh.echo "port created" '''''''''''''''''''''''''' ' install printer driver '''''''''''''''''''''''''' ' If the driver is not signed, one cannot use WMI scripting ' to install the driver. ' Make sure the cat file for the package is copied to the same ' location as the driver objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True Set objDriver = objWMIService.Get("Win32_PrinterDriver") objDriver.Name = PrnDrv objDriver.SupportedPlatform = "Windows NT x86" objDriver.Version = "3" objDriver.DriverPath = DrvPath objDriver.Infname = InfPath intResult = objDriver.AddPrinterDriver(objDriver) ' wsh.echo "driver installed" '''''''''''''''''''''''''' ' Add local printer '''''''''''''''''''''''''' Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_ objPrinter.DriverName = PrnDrv objPrinter.PortName = PortName objPrinter.DeviceID = PrnName objPrinter.Location = PrnLocation objPrinter.Comment = PrnComment objPrinter.Network = True objPrinter.Put_ ' wsh.echo "printer added" 'optional: '''''''''''''''''''''''''' ' Stop & Start Printer Spooler '''''''''''''''''''''''''' Set objSpoolerSvc = objWMIService.Get("Win32_Service.Name='spooler'") iReturn = objSpoolerSvc.StopService() iReturn = objSpoolerSvc.StartService()
June 2nd, 2012 10:33am

Hi, I suggest you ask this question in the Script Forum for further discussion. The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding. Best Regards,Mohammed Imtiyaz Ali
Free Windows Admin Tool Kit Click here and download it now
June 2nd, 2012 1:07pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics