1. Ajouter une imprimante.
WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection("\\PrlnServer1\Xerox300")
WshNetwork.SetDefaultPrinter("\\PrlnServer1\Xerox300")
2. Supprimer une imprimante
lcComputer = "."
loWMIService = GetObject("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colInstalledPrinters = loWMIService.ExecQuery ;
("Select * from Win32_Prlner where DeviceID = 'ScriptedPrlner'")
For Each loPrinter in colInstalledPrinters
loPrinter.Delete;
Next
3. Énumérer tous les imprimantes sur un ordinateur
lcComputer = "."
loWMIService = Getobject("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colInstalledPrinters = loWMIService.ExecQuery ;
("Select * from Win32_Printer")
For Each loPrinter In colInstalledPrinters
?"Nom: " + loPrinter.Name
?"Chemin: " + loPrinter.Location
?"Defaut: " + Transform(loPrinter.Default)
Next
4. Mettre un imprimante par défaut (Windows)
lcComputer = "."
loWMIService = Getobject("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colInstalledPrinters = loWMIService.ExecQuery ;
("Select * from Win32_Printer Where Name = 'ScriptedPrinter'")
For Each loPrinter In colInstalledPrinters
loPrinter.SetDefaultPrinter()
Next
5. Obtenir le status de tous les imprimantes.
clear
lcComputer = "."
loWMIService = GetObject("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colInstalledPrinters = loWMIService.ExecQuery ;
("Select * from Win32_Printer")
For Each loPrinter in colInstalledPrinters
? "Name: " + loPrinter.Name
? "Location: " + loPrinter.Location
do Case
Case loPrinter.PrinterStatus = 1
lcPrinterStatus = "Other"
Case loPrinter.PrinterStatus = 2
lcPrinterStatus = "Unknown"
Case loPrinter.PrinterStatus = 3
lcPrinterStatus = "Idle"
Case loPrinter.PrinterStatus = 4
lcPrinterStatus = "Printing"
Case loPrinter.PrinterStatus = 5
lcPrinterStatus = "Warmup"
Endcase
? "Printer Status: " + lcPrinterStatus
? "Server Name: " + loPrinter.ServerName
? "Share Name: " + loPrinter.ShareName
?
Next
6. Mettre un imprimante en attente
lcComputer = "."
loWMIService = GetObject("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colInstalledPrinters = loWMIService.ExecQuery ;
("Select * from Win32_Printer Where Name = 'ArtDepartmentPrinter'")
For Each loPrinter in colInstalledPrinters
loPrinter.Pause()
Next
7. Repartir une imprimante mise en attente
lcComputer = "."
loWMIService = GetObject("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colInstalledPrinters = loWMIService.ExecQuery ;
("Select * from Win32_Printer Where Name = 'ArtDepartmentPrinter'")
For Each loPrinter in colInstalledPrinters
loPrinter.Retry()
Next
8. Canceller tous les jobs d'une imprimante
lcComputer = "."
loWMIService = GetObject("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colInstalledPrinters = loWMIService.ExecQuery ;
("Select * from Win32_Printer Where Name = 'HP QuietJet'")
For Each loPrinter in colInstalledPrinters
loPrinter.CancelAllJobs()
Next
9. Statistiques des imprimantes
clear
strComputer = "."
objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2")
colPrintQueues = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_Spooler_PrintQueue Where Name <> '_Total'")
For Each objPrintQueue in colPrintQueues
? "Nom: " + objPrintQueue.Name
? "Jobs: " + TRANSFORM(objPrintQueue.Jobs)
? "Courant spooling: " + TRANSFORM(objPrintQueue.JobsSpooling)
? "Maximum spooling: " + TRANSFORM(objPrintQueue.MaxJobsSpooling)
? "Total imprime: " + TRANSFORM(objPrintQueue.TotalJobsPrinted)
? "Erreurs: " + TRANSFORM(objPrintQueue.JobErrors)
? "Pas pret: " + TRANSFORM(objPrintQueue.NotReadyErrors)
? "Erreur manque de papier: " + TRANSFORM(objPrintQueue.OutOfPaperErrors)
?
Next
10. Lister les pilotes d'imprimantes installés
Clear
lcComputer = "."
loWMIService = GetObject("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colInstalledPrinters = loWMIService.ExecQuery ;
("Select * from Win32_PrinterDriver")
For each loPrinter in colInstalledPrinters
?"Config File: " + loPrinter.ConfigFile
?"Data File: " + loPrinter.DataFile
?"Description: " + loPrinter.Description
?"Driver Path: " + loPrinter.DriverPath
?"File Path: " + loPrinter.FilePath
?"Help File: " + loPrinter.HelpFile
?"INF Name: " + loPrinter.InfName
?"Monitor Name: " + loPrinter.MonitorName
?"Name: " + loPrinter.Name
?"OEMUrl: " + loPrinter.OEMUrl
?"Supported Platform: " + loPrinter.SupportedPlatform
?"Version: " + TRANSFORM(loPrinter.Version)
Next