Submitted By: Gamer

Installs a TCP/IP printer port, installs a printer, and then sets the printer to be default. As written the script installs a Brother printer, but you can substitute any printer driver as long as it's in the driver cache.

Visual Basic
Edit|Remove
On Error Resume Next

'SETS 'LOAD DRIVER' PRIVILEGE.


    Set objWMIService = GetObject("Winmgmts:")

    objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True


'SETS PRINTER PORT.


    Set objNewPort = objWMIService.Get _
        ("Win32_TCPIPPrinterPort").SpawnInstance_

    objNewPort.Name = "Brother"

    objNewPort.Protocol = 1

    objNewPort.HostAddress = "192.168.100.7"

    objNewPort.PortNumber = "9100"

    objNewPort.SNMPEnabled = False

    objNewPort.Put_


'SETS PRINTER TO PORT.


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

    objPrinter.DriverName = "Brother HL-1270N"

    objPrinter.PortName   = "Brother"

    objPrinter.DeviceID   = "Brother HL-1270N"

    objPrinter.Location = "Front Office"

    objPrinter.Network = True

    objPrinter.Shared = False

    'objPrinter.ShareName =

    objPrinter.Put_


'SETS PRINTER AS DEFAULT.


    Set colInstalledPrinters =  objWMIService.ExecQuery _
        ("Select * from Win32_Printer Where Name = 'Brother HL-1270N'")

    For Each objPrinter in colInstalledPrinters
        objPrinter.SetDefaultPrinter()

    next