Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

How to use CSV file inputs to add multiple printers in a server?

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use CSV file inputs to add multiple printers in a server?


    I found a VB script in this forum that will help to add a printer. I modified it to get the inputs from user while its getting executed.

    This works well if its for a single printer addition.

    My requirement is to create a CSV file with all the required details for adding printers like name, IP, location, comments, driver location, driver file, model name etc and then use this CSV file in the VB script. When i execute the VB script, it should get the inputs automatically from the csv file and add the printers.

    This is the script. Can anyone help me pls...

    PrnName = InputBox ("Enter the printer name")
    PrnLocation = InputBox ("Enter the location of the printer")
    PrnComment = InputBox ("Enter the comments")
    PrnDrv = InputBox ("Enter the exact driver name")
    DrvPath = InputBox ("Enter the exact driver location")
    InfPath = DrvPath & InputBox ("\INF file name")
    PortIP = InputBox ("Enter the IP address")
    PortName = "IP_" & PortIP

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    ' create ip-printer-port
    Set objNewPort = objWMIService.Get _

    objNewPort.Name = PortName
    objNewPort.Protocol = 1
    objNewPort.HostAddress = PortIP
    objNewPort.PortNumber = "9100"
    objNewPort.SNMPEnabled = False

    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

    wsh.echo "printer added"

    ' Stop & Start Printer Spooler
    Set objSpoolerSvc = objWMIService.Get("Win32_Service.Name='spooler'")
    iReturn = objSpoolerSvc.StopService()
    iReturn = objSpoolerSvc.StartService()

  • #2
    Re: How to use CSV file inputs to add multiple printers in a server?

    Many good examples on
    Use this (the CSV sections) and wrap them around your add printer script:
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    IT Trainer / Consultant
    Ossian Ltd

    ** Remember to give credit where credit is due and leave reputation points where appropriate **


    • #3
      Re: How to use CSV file inputs to add multiple printers in a server?

      thanks for the suggestion. Since i don't know scripting, i am not able to get this work. Can you help me out pls?