''----------------------------------------------'' ''----------------------------------------------'' '' '' '' Script to automate TCP/IP printer installs '' '' (Mitch Sharp - 3/2009) '' '' '' ''----------------------------------------------'' ''----------------------------------------------'' ''----------------------------------------------'' ''--- Configure settings here ---'' ''----------------------------------------------'' strPrinterDisplayName = "Printer name" strPrinterIPAddress = "192.168.50.203" strPrinterDriverINF = "drivers\disk\OEM.INF" strPrinterNameInINF = "Printer name" ''----------------------------------------------'' ''--- Do not edit below this line. ---'' ''----------------------------------------------'' strPrinterPortName = "autoprnt_" & strPrinterIPAddress 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.Network = True objPrinter.Shared = false objPrinter.ShareName = "" objPrinter.Put_ end sub strMBox = MsgBox ("Do you want to install the " & strPrinterDisplayName & " printer?",3) If strMBox = 6 Then ' If they presses Yes MsgBox ("The printer is about to be installed." & vbCrLf & vbCrLf & "You will be prompted when the installation is complete." & vbCrLf & vbCrLf & "Do not press any keys or click anything until prompted!") createPort strPrinterPortName, strPrinterIPAddress strExitCode = oshell.run ("RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b """ & strPrinterDisplayName & """ /r """ & strPrinterPortName & """ /f """ & strPrinterDriverINF & """ /m """ & strPrinterNameInINF & """",,true) If strExitCode = 0 then ' If the install was successful MsgBox ("Printer has been installed!") Else MsgBox ("An error occured... please contact your network administrator." & vbCrLf & vbCrLf & "oshell.run error code: " & strExitCode & "") End If Else ' If they presses anything else MsgBox ("Printer install aborted.") End If