Instalar Impressora num Domínio Via Script
Autor: Fgrazioli | Publicado: 2011-03-12T10:03:00-03:00

Recentemente estive preocupado em instalar uma impressora em vários equipamentos, de uma empresa e seria um tanto cansativo instalar máquina por máquina (manualmente) em mais de 50 micros a mesma impressora.Então eu procurei na net um script que me ajudasse a fazer isso e finalmente consegui achar um que funcionasse.
Detalhamento do Script:
Ao executa-lo&nbsp;o script procura no servidor o driver da impressora (por&nbsp;isso é importante vcs colocarem o driver num caminho de facil localização) a&nbsp;ser instalada, mapeia a porta da impressora(o ip da dita cuja) e ainda&nbsp;define ela como padrão.


Salvem o arquivo na pasta scripts do servidor, e peça pra que todos os&nbsp;usuários executem esse script.


Não esqueçam de salva-lo com a extensão .vbs

=============================SCRIPT===============================



'Verifica se a impressora ja esta instalada
DIM multiPrinter, UNCpath1, UNCpath2, arrPrinters, oPrinters, strPrinter,
boolMapped, i

Set multiPrinter = CreateObject("wscript.network")
Set oPrinters = multiPrinter.EnumPrinterConnections

&nbsp; &nbsp; &nbsp; &nbsp;For i = 0 to oPrinters.Count - 1 Step 2
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If oPrinters.Item(i+1) = "Nome da Impressora de Rede" Then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.Echo "A impressora Nome da Impressora ja esta instalada."
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WScript.quit 'Finaliza o script caso a impressora ja esteja instalada
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end if
&nbsp; &nbsp; &nbsp; &nbsp;Next



PathToDLL = "\\Caminho do driver no servidor"
portloc = "Ip da impressora"
DriverName = "Nome da impressora"
PrintQueueName = ""

set wshshell = wscript.createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")

'Copia e registra DLL para instalação de impressora
fso.copyfile PathToDLL, "c:\windows\Driver.DLL", True
wshshell.run "regsvr32 /s ""c:\windows\Driver.DLL""", , True
wscript.sleep 1000

&nbsp; &nbsp; &nbsp; &nbsp;dim oPort
&nbsp; &nbsp; &nbsp; &nbsp;dim oMaster
&nbsp; &nbsp; &nbsp; &nbsp;set oPort = CreateObject("Port.Port.1")
&nbsp; &nbsp; &nbsp; &nbsp;set oMaster = CreateObject("PrintMaster.PrintMaster.1")


&nbsp; &nbsp; &nbsp; &nbsp; portinput = "IP_" &amp; portloc
&nbsp; &nbsp; &nbsp; &nbsp;oPort.ServerName = ""

&nbsp; &nbsp; &nbsp; &nbsp;sPortExist = False
&nbsp; &nbsp; &nbsp; &nbsp;for each oPort in oMaster.Ports("")
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if oPort.PortName = portinput then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sPortExist = True
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End If
&nbsp; &nbsp; &nbsp; &nbsp;next

&nbsp;If sPortExist = False then

&nbsp; &nbsp; &nbsp; &nbsp;set oPort = CreateObject("Port.Port.1")
&nbsp; &nbsp; &nbsp; &nbsp;oPort.PortName &nbsp; = portinput
&nbsp; &nbsp; &nbsp; &nbsp;oPort.PortType = 1
&nbsp; &nbsp; &nbsp; &nbsp;oPort.HostAddress = portloc
&nbsp; &nbsp; &nbsp; &nbsp;oPort.PortNumber = 9100
&nbsp; &nbsp; &nbsp; &nbsp;oPort.SNMP = false
&nbsp; &nbsp; &nbsp; &nbsp;oMaster.PortAdd oPort
&nbsp; &nbsp; &nbsp; &nbsp;if Err &lt;&gt; 0 then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;msgbox "an error occurred"
&nbsp; &nbsp; &nbsp; &nbsp;end if

&nbsp;End If


&nbsp; &nbsp; &nbsp; &nbsp;dim oPrinter
&nbsp; &nbsp; &nbsp; &nbsp;set oPrinter = CreateObject("Printer.Printer.1")
&nbsp; &nbsp; &nbsp; &nbsp;oPrinter.ServerName &nbsp;= ""
&nbsp; &nbsp; &nbsp; &nbsp;oPrinter.PrinterName = PrintQueueName
&nbsp; &nbsp; &nbsp; &nbsp;oPrinter.DriverName &nbsp;= DriverName
&nbsp; &nbsp; &nbsp; &nbsp;oPrinter.PortName &nbsp; &nbsp;= portinput
&nbsp; &nbsp; &nbsp; &nbsp;oPrinter.DriverPath = "\\Caminho do driver no servidor"
&nbsp; &nbsp; &nbsp; &nbsp;oPrinter.Inffile = "\\Caminho do driver no servidor"

&nbsp; &nbsp; &nbsp; &nbsp;oMaster.PrinterAdd oPrinter

&nbsp; &nbsp; &nbsp; &nbsp;'if Err &lt;&gt; 0 then
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'msgbox "an error occurred: " &amp; Err
&nbsp; &nbsp; &nbsp; &nbsp;'end if


&nbsp; &nbsp;set oport = nothing
&nbsp; &nbsp;set oPrinter = nothing
&nbsp; &nbsp;set oMaster = nothing

&nbsp;msgbox "Impressora instalada com sucesso."

&nbsp; &nbsp;set wshshell = nothing
&nbsp; &nbsp;set fso = nothing

'Seta a impressora como default

Dim objNetwork, strUNCPrinter
strUNCPrinter = "Lexmark E120n"
Set objNetwork = CreateObject("WScript.Network")

' Here is where we set the default printer to strUNCPrinter
objNetwork.SetDefaultPrinter strUNCPrinter

WScript.Quit