Código:
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\SERVIDORIMPRESSAO\IMPRESSORAXYZ"
WshNetwork.SetDefaultPrinter "\\SERVIDORIMPRESSAO\IMPRESSORAXYZ"
Define uma impressora como padrão
Código:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = 'NOMEDAIMPRESSORAAQUI'")
For Each objPrinter in colInstalledPrinters
objPrinter.SetDefaultPrinter()
Next
Remove uma impressora local
Código:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer where DeviceID = 'NOMEDAIMPRESSORAAQUI'")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
Remove uma impressora mapeada
Código: [Selecionar]
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection "\\SERVIDORIMPRESSAO\IMPRESSORAXYZ"
Lista as impressoras da máquina ( saida em dialog )
Código:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
Wscript.Echo "Nome: " & objPrinter.Name
Wscript.Echo "Local: " & objPrinter.Location
Wscript.Echo "Padrão: " & objPrinter.Default
Next
Renomeia nome de impressora para padronização
Código:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where DeviceID = 'HP LaserJet 4Si M Series PCL6'")
For Each objPrinter in colPrinters
objPrinter.RenamePrinter("ArtDepartmentPrinter")
Next
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where DeviceID = 'NOVONOMEDAIMPRESSORA' ")
For Each objPrinter in colPrinters
objPrinter.ShareName = "ArtDepartmentPrinter"
objPrinter.Put_
Next
Instala impressora de rede e ativa compartilhamento
Código:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = "HPFINANCEIRO"
objPrinter.PortName = "IP_192.168.0.250"
objPrinter.DeviceID = "ScriptedPrinter"
objPrinter.Location = "Departamento Financeiro"
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.ShareName = "HPFINANCEIRO"
objPrinter.Put_
Resume serviços pausados em uma impressora
Código:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = 'NOMEDAIMPRESSORAAQUI'")
For Each objPrinter in colInstalledPrinters
ObjPrinter.Resume()
Next
Remove todos os trabalhos grandes da fila
Código:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery _
("Select * from Win32_PrintJob Where Size > 1000000")
For Each objPrintJob in colPrintJobs
objPrintJob.Delete_
Next
Remove portas de impressão sem uso
Código:
Set objDictionary = CreateObject("Scripting.Dictionary")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colPrinters
objDictionary.Add objPrinter.PortName, objPrinter.PortName
Next
Set colPorts = objWMIService.ExecQuery _
("Select * from Win32_TCPIPPrinterPort")
For Each objPort in colPorts
If objDictionary.Exists(objPort.Name) Then
Else
ObjPort.Delete_
End If
Next
Automatizando instalação de drivers
Código:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
Set objDriver = objWMIService.Get("Win32_PrinterDriver")
objDriver.Name = "NOVA IMPRESSORA MODELO XY3000"
objDriver.SupportedPlatform = "Windows NT x86"
objDriver.Version = "3"
objDriverPath = "C:\Scripts\NewPrinter.dll"
objInfname = "C:\Scripts\NewPrinter.inf"
intResult = objDriver.AddPrinterDriver(objDriver)