begin process at 2008 05 12 12:41:26
1 170 288 membres
187 nouveaux aujourd'hui
13 958 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

FONCTIONS POUR IMPRIMANTES AVEC WINDOWS SCRIPTING


Information sur la source

Catégorie :API-OLE Classé sous : fonctions, imprimantes Niveau : Débutant Date de création : 15/10/2004 Date de mise à jour : 16/10/2004 11:58:22 Vu : 4 940

Note :
Aucune note

Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

Description

Ajouter un imprimante de reseau sur un ordinateur client avec Windows Scripting

Source

  • 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
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


16 octobre 2004 00:13:57 :
Ajouter des fonctions
16 octobre 2004 11:58:22 :
Ajouté des fonctions.
    Aucun commentaire pour le moment.

Ajouter un commentaire

Appels d'offres

Pub



CalendriCode

Mai 2008
LMMJVSD
   1234
567891011
12131415161718
19202122232425
262728293031 

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS