begin process at 2012 05 22 12:29:21
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

API-OLE

 > FONCTIONS POUR IMPRIMANTES AVEC WINDOWS SCRIPTING

FONCTIONS POUR IMPRIMANTES AVEC WINDOWS SCRIPTING


 Information sur la source

Note :
Aucune note
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 :9 373

Auteur : Mike Gagnon

Ecrire un message privé
Site perso
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





 Historique

16 octobre 2004 00:13:57 :
Ajouter des fonctions
16 octobre 2004 11:58:22 :
Ajouté des fonctions.

 Sources du même auteur

COMMENT REMPLIR UN COURRIEL ET OUVRIR LE PROGRAMME PRET À PA...
COMMENT CRÉER UN DOCUMENT MHTML AVEC CDO
AJOUTER ET SUPPRIMER UNE ENTRÉ DANS LE REGISTRE DE WINDOWS ...
COMMENT PROTÉGER LES TABLES SANS UTILISER L'ENCRYPTAGE.
COMMENT DÉTERMINER SI UN DLL EST ENREGITRÉ SUR UN ORDINATEUR

 Sources de la même categorie

AUTOMATION DE WORD AVEC VFP par AbaqueInside
LISTER LES ADRESSES IP DE LA MACHINE par FrancisFaure
OUVRIR UN DOCUMENT WORD PAR AUTOMATION ET FAIRE UNE FUSION A... par leissler
[VFP]CLASSE SYSTEMTIME par FredArmoni
Source avec Zip SPLASHSCREEN TYPE ALERTE D'OUTLOOK2003 par FredArmoni

 Sources en rapport avec celle ci

FONCTIONS UTILES SUR LES FICHIERS ET DOSSIERS AVEC WINDOWS S... par Mike Gagnon

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,733 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales