ejemplo de control de la cola de impresión por programa wxp • esscripts - programas - abre tus...
Post on 30-Jul-2015
90 Views
Preview:
TRANSCRIPT
Autoit en Español (www.Autoit.es)
Descarga programas libres y Open-Source. Añade tu programa a la librería de Scripts en Autoit.es
Obviar
Búsqueda avanzada
Índice general ‹ Autoit en Español ‹ esScripts - Programas - Abre tus creaciones maravillosasCambiar tamaño de la fuenteImprimir vista
FAQRegistrarseIdentificarse
Ejemplo de control de la cola de Impresión por programa WXP
Publicar una respuesta
7 mensajes • Página 1 de 1
Ejemplo de control de la cola de Impresión por programa WXP
por BasicOs » 24 Nov 2006, 02:44
Cada vez que mandamos algo a imprimir sale botón de aceptar con el trabajo de la cola de impresión, puedemodificarse para hacer un LOG de las impresoras
;Author Basicos http://www.autoit.es 24/09/06$strcomputer = "."
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & "\\" &$strcomputer & "\root\cimv2")$colPrintJobs = $objWMIService.ExecNotificationQuery("Select * From__InstanceCreationEvent " _& "Within 1 Where TargetInstance ISA 'Win32_PrintJob'")
$OEvent=ObjEvent("AutoIt.Error","nothing"); = OnError Resume Next
While 1
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
1 de 22 12/02/2012 12:00 a.m.
Printing()sleep(100)WEnd
Func Printing()If IsObj($objWMIService) then$objPrintJob = $colPrintJobs.NextEvent$objPrint = $objPrintJob.TargetInstance.TotalPagesmsgbox(0,"totalpages",$objPrint)If $objPrint > 1 Then$objPrintJob.TargetInstance.Pause$msg = MsgBox (17, "Print Notification",$objPrintJob.TargetInstance.Document, 10)If $msg = 1 Then $objPrintJob.TargetInstance.ResumeIf $msg = 2 Then $objPrintJob.TargetInstance.CancelEndIfElseMsgBox(0, "Error", "Unable to connect to PrintJob Creation Event")ExitEndIfEndFunc
En Español http://www.autoit.es. Crea Programas únicos con AutoIt. ¡Saltate la barrera de lo imposible enprogramación!!
BasicOsSite Admin Mensajes: 1587Registrado: 21 Nov 2006, 19:24Ubicación: El Internet - (Canarias, España)
Sitio web
Arriba
Re: Ejemplo de control de la cola de Impresión por programa WXP
por Dick_ » 29 Sep 2010, 03:13
Hola BasicOs, si bien este post es viejo, respondo aqui porque mi consulta tiene que ver con este codigo, tecomento, yo estoy tratando de hacer un programita que intercepte las impresiones que se envian desde unared (ciber) y que pida confirmacion en el servidor para imprimir. Parto del ejemplo que pusiste aqui pero nome funciona el cancel sabes porque puede ser? ya que el resume y el pause andan ok. y si tenes un link parasacar mas info sobre el tema te lo agradeceria.
Dick_ Mensajes: 4Registrado: 29 Sep 2010, 03:06
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
2 de 22 12/02/2012 12:00 a.m.
Arriba
Re: Ejemplo de control de la cola de Impresión por programa WXP
por BasicOs » 29 Sep 2010, 10:56
Hola!Mirando un poco a ver que había encontré una selección de las cosas que se puedan hacer con las impresoras.Realmente es la incorporación de un objeto Wmi al código Autoit, con lo que podemos usarlo facilmente.Siguiendo el ejemplo que viste arriba, solo hay que reemplazar un código por otro de esa manera. Si te falla dealguna manera, debes comprobar los objetos Wmi directamente (puede ser a través del código de abajo, o deun testeador de wmi que puedes buscar en softonic o google, ahora no te puedo recomendar uno, pero si loencuentras y lo comunicas puede ayudarnos).Está en Inglés pero lo que importa realmente el código es parecido en este caso:
Limpiando la cola de impresión. Borra todos los trabajos de la impresora llamada HP QuietJet
Código: Seleccionar todoEn WsScript
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = 'HP QuietJet'")
For Each objPrinter in colInstalledPrinters
objPrinter.CancelAllJobs()
Next
-->>Lo mismo en Autoit:
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\" & $strComputer & " ootcimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer
Where Name = 'HP LaserJet 3200 Series PCL'")
For $objPrinter in $colInstalledPrinters
$objPrinter.CancelAllJobs()
Next
Delete All Large Print Jobs (Borrar todos los trabajos de impresora grandes) Deletes all print jobslarger than 1 megabyte. (Borra todos los trabajos de impresora mayores de 1 mega)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 colPrintJobsobjPrintJob.Delete_
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
3 de 22 12/02/2012 12:00 a.m.
Next
Delete All Printers on a Print Server (Borrar todas las impresoras de un servidor de impresión)Deletes all the printers from a print server.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrintersobjPrinter.Delete_Next
Deletes all HP QuietJet printers installed on a computer.
Delete Specific PrintersstrComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_Printer Where DriverName = 'HP QuietJet'")
For Each objPrinter in colInstalledPrintersobjPrinter.Delete_Next
Install Multiple Printers for One Print Device
Installs two logical network printers (with different printer priorities) for the same physical printdevice.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = "HP LaserJet 4000 Series PS"objPrinter.PortName = "IP_169.254.110.160"objPrinter.DeviceID = "PublicPrinter"objPrinter.Location = "USA/Redmond/Building 37/Room 114"objPrinter.Network = TrueobjPrinter.Shared = TrueobjPrinter.ShareName = "PublicPrinter"objPrinter.Put_
objPrinter.DriverName = "HP LaserJet 4000 Series PS"
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
4 de 22 12/02/2012 12:00 a.m.
objPrinter.PortName = "IP_169.254.110.160"objPrinter.DeviceID = "PrivatePrinter"objPrinter.Location = "USA/Redmond/Building 37/Room 114"objPrinter.Priority = 2objPrinter.Network = TrueobjPrinter.Shared = TrueobjPrinter.Hidden = TrueobjPrinter.ShareName = "PrivatePrinter"objPrinter.Put_
Install a Printer
Installs a logical network printer on a print server.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = "HP LaserJet 4000 Series PS"objPrinter.PortName = "IP_169.254.110.160"objPrinter.DeviceID = "ScriptedPrinter"objPrinter.Location = "USA/Redmond/Building 37/Room 114"objPrinter.Network = TrueobjPrinter.Shared = TrueobjPrinter.ShareName = "ScriptedPrinter"objPrinter.Put_
List All Published Printers
Returns a list of all the printers published in Active Directory.Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")Set objCommand = CreateObject("ADODB.Command")objConnection.Provider = "ADsDSOObject"objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnectionobjCommand.CommandText = "Select printerName, serverName from " _& " 'LDAP://DC=fabrikam,DC=com' where objectClass='printQueue'"objCommand.Properties("Page Size") = 1000objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREESet objRecordSet = objCommand.ExecuteobjRecordSet.MoveFirst
Do Until objRecordSet.EOFWscript.Echo "Printer Name: " & objRecordSet.Fields("printerName").ValueWscript.Echo "Server Name: " & objRecordSet.Fields("serverName").Value
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
5 de 22 12/02/2012 12:00 a.m.
objRecordSet.MoveNextLoop
List Printer Capabilities
Lists properties and capabilities for all the printers installed on a computerstrComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_PrinterConfiguration")
For Each objPrinter in colInstalledPrintersWscript.Echo "Name: " & objPrinter.NameWscript.Echo "Collate: " & objPrinter.CollateWscript.Echo "Copies: " & objPrinter.CopiesWscript.Echo "Driver Version: " & objPrinter.DriverVersionWscript.Echo "Duplex: " & objPrinter.DuplexWscript.Echo "Horizontal Resolution: " & _objPrinter.HorizontalResolutionIf objPrinter.Orientation = 1 ThenstrOrientation = "Portrait"ElsestrOrientation = "Landscape"End IfWscript.Echo "Orientation : " & strOrientationWscript.Echo "Paper Length: " & objPrinter.PaperLength / 254Wscript.Echo "Paper Width: " & objPrinter.PaperWidth / 254Wscript.Echo "Print Quality: " & objPrinter.PrintQualityWscript.Echo "Scale: " & objPrinter.ScaleWscript.Echo "Specification Version: " & _objPrinter.SpecificationVersionIf objPrinter.TTOption = 1 ThenstrTTOption = "Print TrueType fonts as graphics."Elseif objPrinter.TTOption = 2 ThenstrTTOption = "Download TrueType fonts as soft fonts."ElsestrTTOption = "Substitute device fonts for TrueType fonts."End IfWscript.Echo "True Type Option: " & strTTOptionWscript.Echo "Vertical Resolution: " & objPrinter.VerticalResolutionNext
List Print Queue Statistics
Returns total number of jobs, total number of pages, and largest job for all print queues on acomputer.strComputer = "."
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
6 de 22 12/02/2012 12:00 a.m.
Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery _("Select * from Win32_PrintJob")
For Each objPrintJob in colPrintJobsintTotalJobs = intTotalJobs + 1intTotalPages = intTotalPages + objPrintJob.TotalPagesIf objPrintJob.TotalPages > intMaxPrintJob ThenintMaxPrintJob = objPrintJob.TotalPagesEnd IfNext
Wscript.Echo "Total print jobs in queue: " & intTotalJobsWscript.Echo "Total pages in queue: " & intTotalPagesWscript.Echo "Largest print job in queue: " & intMaxPrintJob
Uses cooked performance counters to retrieve data such as total number of jobs printed and totalnumber of printing errors for each print queue on a computer.
List Print Queue StatisticsstrComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintQueues = objWMIService.ExecQuery _("Select * from Win32_PerfFormattedData_Spooler_PrintQueue Where " & _"Name <> '_Total'")
For Each objPrintQueue in colPrintQueuesWscript.Echo "Name: " & objPrintQueue.NameWscript.Echo "Jobs: " & objPrintQueue.JobsWscript.Echo "Current jobs spooling: " & objPrintQueue.JobsSpoolingWscript.Echo "Maximum jobs spooling: " & objPrintQueue.MaxJobsSpoolingWscript.Echo "Total jobs printed: " & objPrintQueue.TotalJobsPrintedWscript.Echo "Job errors: " & objPrintQueue.JobErrorsWscript.Echo "Not ready errors: " & objPrintQueue.NotReadyErrorsWscript.Echo "Out of paper errors: " & objPrintQueue.OutOfPaperErrorsNext
Monitor Printer Status
Checks the status for each printer on a computer, and issues an alert if any of these printers havestopped.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
7 de 22 12/02/2012 12:00 a.m.
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_Printer Where PrinterStatus = '1' " _& "or PrinterStatus = '2'")
If colInstalledPrinters.Count = 0 ThenWscript.Echo "All printers are functioning correctly."ElseFor Each objPrinter in colInstalledPrintersWscript.Echo "Printer " & objprinter.Name & " is not responding."NextEnd If
Monitor Printer Status
Displays current status for all printers on a computer.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrintersWscript.Echo "Name: " & objPrinter.NameWscript.Echo "Location: " & objPrinter.LocationSelect Case objPrinter.PrinterStatusCase 1strPrinterStatus = "Other"Case 2strPrinterStatus = "Unknown"Case 3strPrinterStatus = "Idle"Case 4strPrinterStatus = "Printing"Case 5strPrinterStatus = "Warmup"End SelectWscript.Echo "Printer Status: " & strPrinterStatusWscript.Echo "Server Name: " & objPrinter.ServerNameWscript.Echo "Share Name: " & objPrinter.ShareNameWscript.EchoNext
Modify Printer Availability
Configures a printer so that documents can only be printed between 8:00 AM and 6:00 PM.dtmStartTime= "********080000.000000+000"dtmEndTime= "********180000.000000+000"
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
8 de 22 12/02/2012 12:00 a.m.
strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _("Select * From Win32_Printer Where DeviceID = 'ArtDepartmentPrinter' ")
For Each objPrinter in colPrintersobjPrinter.StartTime = dtmStartTimeobjPrinter.UntilTime = dtmEndTimeobjPrinter.Put_Next
Modify Print Job Priority
Uses ADSI to change the priority of current print jobs based on the size of those print jobs.Set objPrinter = GetObject _("WinNT://atl-dc-02/ArtDepartmentPrinter, printqueue")
For Each objPrintJob in objPrinter.PrintJobsIf objPrintJob.Size > 400000 ThenobjPrintJob.Put "Priority" , 2objPrintJob.SetInfoElseobjPrintJob.Put "Priority" , 3objPrintJob.SetInfoEnd IfNext
Modify Print Job Start Time
Uses ADSI to change the start time for all print jobs larger than 400K to 2:00 AM.Set objPrinter = GetObject("WinNT://atl-dc-02/ArtDepartmentPrinter,printqueue")
For Each objPrintQueue in objPrinter.PrintJobsIf objPrintQueue.Size > 400000 ThenobjPrintQueue.Put "StartTime" , TimeValue("2:00:00 AM")objPrintQueue.SetInfoEnd IfNext
Monitor Print Job Status
Returns the job ID, user name, and total pages for each print job on a computer.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
9 de 22 12/02/2012 12:00 a.m.
Set colPrintJobs = objWMIService.ExecQuery _("Select * from Win32_PrintJob")
Wscript.Echo "Print Queue, Job ID, Owner, Total Pages"
For Each objPrintJob in colPrintJobsstrPrinter = Split(objPrintJob.Name,",",-1,1)Wscript.Echo strPrinter(0) & ", " & _objPrintJob.JobID & ", " & objPrintJob.Owner & ", " _& objPrintJob.TotalPagesNext
Modify Printer Locations
Uses ADSI to configure the location attribute for all the printers in a specified OU.Set objOU = GetObject("LDAP://OU = Finance, DC = fabrikam, DC = com")objOU.Filter = Array("printqueue")
For Each objPrintQueue In objOUobjPrintQueue.Put "Location" , "USA/Redmond/Finance Building"objPrintQueue.SetInfoNext
Modify Printer Priority
Sets the priority for a printer to 2.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _("Select * From Win32_Printer where DeviceID = 'ArtDepartmentPrinter' ")
For Each objPrinter in colPrintersobjPrinter.Priority = 2objPrinter.Put_Next
Monitor Print Queue Times
Identifies any print jobs that have been in the print queue for more than 15 minutes.Const USE_LOCAL_TIME = True
Set DateTime = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
10 de 22 12/02/2012 12:00 a.m.
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_PrintJob")
Wscript.Echo "Print Queue, Job ID, TimeSubmitted, Total Pages"
For Each objPrinter in colInstalledPrintersDateTime.Value = objPrinter.TimeSubmitteddtmActualTime = DateTime.GetVarDate(USE_LOCAL_TIME)TimeinQueue = DateDiff("n", actualTime, Now)If TimeinQueue > 15 ThenstrPrinterName = Split(objPrinter.Name,",",-1,1)Wscript.Echo strPrinterName(0) & ", " _& objPrinter.JobID & ", " & dtmActualTime & ", " & _objPrinter.TotalPagesEnd IfNext
Monitor Print Queues
Uses cooked performance counters to return the number of jobs currently in each print queue ona computer.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintQueues = objWMIService.ExecQuery _("Select * from Win32_PerfFormattedData_Spooler_PrintQueue " & _"Where Name <> '_Total'")
For Each objPrintQueue in colPrintQueuesWscript.Echo "Name: " & objPrintQueue.NameWscript.Echo "Current jobs: " & objPrintQueue.JobsNext
Monitor Printers with a Temporary Event Subscription
Uses a temporary event consumer to issues alerts any time a printer changes status.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService. _ExecNotificationQuery("Select * from __instancemodificationevent " _& "within 30 where TargetInstance isa 'Win32_Printer'")i = 0
Do While i = 0Set objPrinter = colPrinters.NextEvent
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
11 de 22 12/02/2012 12:00 a.m.
If objPrinter.TargetInstance.PrinterStatus <> _objPrinter.PreviousInstance.PrinterStatus ThenSelect Case objPrinter.TargetInstance.PrinterStatusCase 1 strCurrentState = "Other"Case 2 strCurrentState = "Unknown"Case 3 strCurrentState = "Idle"Case 4 strCurrentState = "Printing"Case 5 strCurrentState = "Warming Up"End SelectSelect Case objPrinter.PreviousInstance.PrinterStatusCase 1 strPreviousState = "Other"Case 2 strPreviousState = "Unknown"Case 3 strPreviousState = "Idle"Case 4 strPreviousState = "Printing"Case 5 strPreviousState = "Warming Up"End SelectWscript.Echo objPrinter.TargetInstance.Name _& " is " & strCurrentState _& ". The printer previously was " & strPreviousState & "."End IfLoop
Monitor Spooler Print Queue Performance
Uses cooked performance counters to return information about print jobs spooled on a printserver.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")set objRefresher = CreateObject("WbemScripting.SWbemRefresher")Set colItems = objRefresher.AddEnum _(objWMIService, "Win32_PerfFormattedData_Spooler_PrintQueue").objectSetobjRefresher.Refresh
For i = 1 to 5For Each objItem in colItemsWscript.Echo "Add Network Printer Calls: " & _objItem.AddNetworkPrinterCallsWscript.Echo "Bytes Printed Per Second: " & objItem.BytesPrintedPersecWscript.Echo "Caption: " & objItem.CaptionWscript.Echo "Description: " & objItem.DescriptionWscript.Echo "Enumerate Network Printer Calls: " & _objItem.EnumerateNetworkPrinterCallsWscript.Echo "Job Errors: " & objItem.JobErrorsWscript.Echo "Jobs: " & objItem.JobsWscript.Echo "Jobs Spooling: " & objItem.JobsSpoolingWscript.Echo "Maximum Jobs Spooling: " & objItem.MaxJobsSpoolingWscript.Echo "Maximum References: " & objItem.MaxReferencesWscript.Echo "Name: " & objItem.NameWscript.Echo "Not-Ready Errors: " & objItem.NotReadyErrors
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
12 de 22 12/02/2012 12:00 a.m.
Wscript.Echo "Out-of-Paper Errors: " & objItem.OutofPaperErrorsWscript.Echo "References: " & objItem.ReferencesWscript.Echo "Total Jobs Printed: " & objItem.TotalJobsPrintedWscript.Echo "Total Pages Printed: " & objItem.TotalPagesPrintedWscript.Sleep 2000objRefresher.RefreshNextNext
Monitor the Print Service
Returns the status of the Spooler service (running, stopped, paused, etc.).strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _("Select * from Win32_Service Where Name = 'Spooler'")
For Each objService in colRunningServicesWscript.Echo objService.DisplayName & " -- " & objService.StateNext
Notify Users When a Print Queue is Purged
Uses Msg.exe to send a network alert to any users who had documents in a print queue about tobe purged. After sending the alerts, the script purges the print queue.Set WshShell = Wscript.CreateObject("Wscript.Shell")Set objDictionary = CreateObject("Scripting.Dictionary")
strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrintJobs = objWMIService.ExecQuery _("Select * from Win32_PrintJob")
For Each objPrintJob in colInstalledPrintJobsstrPrinterName = Split(objPrintJob.Name,",",-1,1)If objDictionary.Exists(objPrintJob.Notify) ThenElseobjDictionary.Add objPrintJob.Notify, strPrinterName(0)End IfNext
arrKeys = objDictionary.KeysarrItems = objDictionary.Items
For i = 0 to objDictionary.Count - 1
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
13 de 22 12/02/2012 12:00 a.m.
Message = "The documents you were printing on printer "Message = Message & arrItems(i)Message = Message & " had to be deleted from the print queue. "Message = Message & "You will need to reprint these documents."CommandString = "%comspec% /c msg " & arrKeys(i) & " " & Chr(34) _& Message & Chr(34)WshShell.Run CommandString, 0, TrueNext
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_Printer")For Each objPrinter in colInstalledPrintersobjPrinter.CancelAllJobs()Next
Pause All Print Jobs
Pauses all the print jobs on a print server.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery _("Select * from Win32_PrintJob")
For Each objPrintJob in colPrintJobsobjPrintJob.PauseNext
Pause a Printer
Pauses a printer named ArtDepartmentPrinter.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_Printer Where Name = 'ArtDepartmentPrinter'")
For Each objPrinter in colInstalledPrintersObjPrinter.Pause()Next
Pause All Printers with Empty Print Queues
Pauses any printers that have no pending print jobs.strComputer = "."Set objWMIService = GetObject("winmgmts:" _
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
14 de 22 12/02/2012 12:00 a.m.
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrintersSet colPrintJobs = objWMIService.ExecQuery _("Select * from Win32_PerfFormattedData_Spooler_PrintQueue " _& "Where Name = '" & objPrinter.Name & "'")For Each objPrintQueue in colPrintJobsIf objPrintQueue.Jobs = 0 and objPrintQueue.Name <> "_Total" ThenobjPrinter.Pause()End IfNextNext
Purge a Print Queue
Deletes all the print jobs for a printer named HP QuietJet.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_Printer Where Name = 'HP QuietJet'")
For Each objPrinter in colInstalledPrintersobjPrinter.CancelAllJobs()Next
Resume All Print Jobs
Resumes all the print jobs on a computer.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs = objWMIService.ExecQuery _("Select * from Win32_PrintJob")
For Each objPrintJob in colPrintJobsobjPrintJob.ResumeNext
Resume All Paused Printers
Resumes all the paused printers on a print server.Const PRINTER_IS_PAUSED = 8
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
15 de 22 12/02/2012 12:00 a.m.
strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_Printer where ExtendedPrinterStatus = 8")
For Each objPrinter in colInstalledPrintersObjPrinter.Resume()Next
Resume a Paused Printer
Resumes a paused printer.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _("Select * from Win32_Printer Where Name = 'ArtDepartmentPrinter'")
For Each objPrinter in colInstalledPrintersObjPrinter.Resume()Next
Rename a Printer Published in Active Directory
Uses the MoveHere method to rename a published printer in an OU.Set objOU = GetObject("LDAP://ou=HR,dc=NA,dc=fabrikam,dc=com")
objOU.MoveHere _"LDAP://cn=Printer1,ou=HR,dc=NA,dc=fabrikam,dc=com", "cn=HRPrn1"
Search Active Directory for Specific Printers
Searches Active Directory for all printers with a priority of 2.Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"objConnection.Open "Active Directory Provider"Set objCOmmand.ActiveConnection = objConnectionobjCommand.CommandText = "Select printerName, serverName from " _& "'LDAP://DC=fabrikam,DC=com' where objectClass='printQueue' and " _& " Priority = 2 "
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
16 de 22 12/02/2012 12:00 a.m.
objCommand.Properties("Page Size") = 1000objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.ExecuteobjRecordSet.MoveFirst
Do Until objRecordSet.EOFWscript.Echo "Printer Name: " & objRecordSet.Fields("printerName").ValueWscript.Echo "Server Name: " & objRecordSet.Fields("serverName").ValueobjRecordSet.MoveNextLoop
Transfer Print Jobs to a Different Print Queue
Changes the TCP/IP printer port for a logical printer, which has the net effect of transferringexisting print jobs to the new printer port, and thus to a different printer.strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get _("Win32_Printer.DeviceID='ArtDepartmentPrinter'")
objPrinter.PortName = "IP_192.168.1.10"objPrinter.Put_
Update Printer Locations
Uses ADSI to update the location attribute for all printers in a specified OU.Set objOU = GetObject("LDAP://OU=Finance, DC=fabrikam, DC=com")objOU.Filter = Array("printqueue")
For Each objPrintQueue In objOUstrNewLocation = "Redmond/" & objPrintQueue.LocationobjPrintQueue.Put "Location" , strNewLocationobjPrintQueue.SetInfoNext
Enlace original: http://mirror1.activexperts.com/activmo ... #DALPJ.htm
Este es otro enlace de Wmi para enviar Sms con la herramienta de este fabricante:http://es.activexperts.com/xmstoolkit/En este tópico comentan, que quizás debes recuperar el nombre del impresora con una función y luego usarlo,porque el nombre puede que esté mal???http://www.autoitscript.com/forum/index.php?showtopic=33035&st=0&p=278538&hl=$objPrintJob&fromsearch=1&#entry278538Salu22:)EDIT: Otros ejemplos de como serían unas funciones de uso de impresoras Creditos a Danny35d :
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
17 de 22 12/02/2012 12:00 a.m.
Código: Seleccionar todoFunc _ListPrinters($hnwd, $iDefault = 1, $sShowMsgBox = 0, $strComputer =
"localhost")
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$ret = ""
If $sShowMsgBox Then MsgBox(0, "", "This may take a moment...Please wait until
the search for printer share is complete.", 2)
If $iDefault Then GUICtrlSetData($Label1, '')
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
If Not @error = 0 Then
MsgBox(48, "ERROR", "No Printers Found. Possible issues: " & @CRLF _
& "" & @CRLF _
& " 1. The Windows Print Server name has been entered in
incorrectly." & @CRLF _
& " 2. You are trying to access a Novell Server. This utility does
not support Novell Print Servers." & @CRLF _
& " 3. There are no printers shared on the Windows Print Server you
selected.")
Return('')
EndIf
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
_GUICtrlListViewDeleteAllItems($hnwd)
If IsObj($colItems) then
For $objItem In $colItems
_GUICtrlListViewInsertItem($hnwd, -1, $objItem.Caption)
If StringLower($strComputer) <> 'localhost' Then $ret &= '|' &
$objItem.Caption
If $iDefault And $objItem.Default == -1 Then GUICtrlSetData($Label1,
StringLeft($objItem.Caption, 30))
Next
If $ret <> '' Then IniWrite($IniFile, $strComputer, 'PrinterList',
StringTrimLeft($ret, 1))
Else
Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Printer" )
Endif
EndFunc
Func _AddPrinter($PRINTERSHARE, $Server)
$Pos = _ChildWindowCenter('Add Network Printers', 305, 131)
ProgressOn('Add Printer', 'Adding Printer', '', $Pos[0], $Pos[1])
For $x = 1 To $PRINTERSHARE[0]
$ret = '\\' & StringReplace($Server, '\', '') & '\' &
_GUICtrlListViewGetItemText($ListView2, $PRINTERSHARE[$x])
ProgressSet(Int(($x/$PRINTERSHARE[0]) * 100), $ret)
RunWait("rundll32 printui.dll,PrintUIEntry /in /q /n" & $ret)
_GUICtrlListViewSetItemSelState($ListView2, $PRINTERSHARE[$x], 0)
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
18 de 22 12/02/2012 12:00 a.m.
Next
Sleep(1500)
_ListPrinters($ListView1)
ProgressOff()
EndFunc
Func _RemovePrinter($PRINTERSHARE)
$Pos = _ChildWindowCenter('Network Printer Utility', 305, 131)
ProgressOn('Remove Printer', 'Removing Printer', '', $Pos[0], $Pos[1])
For $x = 1 To $PRINTERSHARE[0]
$ret = _GUICtrlListViewGetItemText($ListView1, $PRINTERSHARE[$x])
ProgressSet(Int(($x/$PRINTERSHARE[0]) * 100), $ret)
If StringLeft($ret, 2) == '\\' Then
RunWait(@ComSpec & ' /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /gd /dn /q /n "'
& $ret & '"', '', @SW_HIDE) ; Remove Network Printer
Else
RunWait(@ComSpec & ' /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /dl /c\\' &
@ComputerName & ' /n "' & $ret & '"', '', @SW_HIDE) ; Remove Local Printer
EndIf
_GUICtrlListViewSetItemSelState($ListView1, $PRINTERSHARE[$x], 0)
Next
Sleep(1500)
_ListPrinters($ListView1, 1)
ProgressOff()
EndFunc
Func _ChangePrinter($PRINTERSHARE)
RunWait(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /y /n " & '"' &
$PRINTERSHARE & '"', "", @SW_HIDE)
GUICtrlSetData($Label1, StringLeft($PRINTERSHARE, 30))
EndFunc
Func _ChildWindowCenter($sParentTitle, $ChildWidth, $ChildHeight)
Opt("WinTitleMatchMode", 4)
$taskbar = WinGetPos("classname=Shell_TrayWnd")
$MainGUIsize = WinGetPos($sParentTitle)
$MainGUIsize[0] = ($MainGUIsize[2] - $ChildWidth) / 2 + $MainGUIsize[0]
$MainGUIsize[1] = ($MainGUIsize[3] - $ChildHeight) /2 + $MainGUIsize[1]
If $MainGUIsize[0] < 0 Then $MainGUIsize[0] = 0
If $MainGUIsize[0] > (@DesktopWidth - $ChildWidth) Then $MainGUIsize[0] =
@DesktopWidth - $ChildWidth
If $MainGUIsize[1] < 0 Then $MainGUIsize[1] = 0
If $MainGUIsize[1] > ($taskbar[1] - $ChildHeight) Then $MainGUIsize[1] =
$taskbar[1] - $ChildHeight
Opt("WinTitleMatchMode", 1)
Return($MainGUIsize)
EndFunc
En Español http://www.autoit.es. Crea Programas únicos con AutoIt. ¡Saltate la barrera de lo imposible enprogramación!!
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
19 de 22 12/02/2012 12:00 a.m.
BasicOsSite Admin Mensajes: 1587Registrado: 21 Nov 2006, 19:24Ubicación: El Internet - (Canarias, España)
Sitio web
Arriba
Re: Ejemplo de control de la cola de Impresión por programa WXP
por Dick_ » 01 Oct 2010, 03:39
BasicOs realmente sos un kapo y lo mejor es que estas presto para ayudar y contestar a todas las preguntasque se te plantean.te comento que el programa lo hice andar cambiando el cancel por delete_ anda de 10 ahora el desafio estrabajarlo un poco para lograr un control de impresion donde me avise desde que cliente se esta enviando laimpresion, cuantas hojas son y de paso que grabe en un log para que el operador del ciber no nos mienta lacantidad de hojas que imprimio.
muchas gracias por la info.saludos.
Dick_ Mensajes: 4Registrado: 29 Sep 2010, 03:06
Arriba
Re: Ejemplo de control de la cola de Impresión por programa WXP
por BasicOs » 01 Oct 2010, 13:02
No hay de que, espero ver ese fantástico programa que parece una joya!!Salu22)En Español http://www.autoit.es. Crea Programas únicos con AutoIt. ¡Saltate la barrera de lo imposible enprogramación!!
BasicOsSite Admin Mensajes: 1587
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
20 de 22 12/02/2012 12:00 a.m.
Registrado: 21 Nov 2006, 19:24Ubicación: El Internet - (Canarias, España)
Sitio web
Arriba
Re: Ejemplo de control de la cola de Impresión por programa
por jamaro » 20 Sep 2011, 08:46
¿Y ya podemos ver algo de código para poder controlar las páginas que se han imprimido?
He estado buscando información para controlar las páginas imprimidas (en impresora local) pero todavía nosé cómo.
Saludos
EDITO: Entre otras cosas he encontrado esto de ALLAPI, pero no sé si se puede utilizar en Autoi ni cómo.
jamaroHacker del Foro Mensajes: 195Registrado: 03 Nov 2010, 23:04
Arriba
Re: Ejemplo de control de la cola de Impresión por programa
por jamaro » 20 Sep 2011, 13:22
Después de releer este hilo y probar el código expuesto, creo que el camino a seguir en Autoit para registrar elnúmero de copias impresas de una impresora local es utilizando: Win32_PrintJob
De todos modos soy todo oidos y ojos para ayudar a enfocar el código
jamaroHacker del Foro Mensajes: 195Registrado: 03 Nov 2010, 23:04
Arriba
Mostrar mensajes previos: Ordenar por
Publicar una respuesta7 mensajes • Página 1 de 1
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
21 de 22 12/02/2012 12:00 a.m.
Volver a esScripts - Programas - Abre tus creaciones maravillosas
Saltar a:
¿Quién está conectado?
Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 3 invitados
Índice generalEl Equipo • Borrar todas las cookies del Sitio • Todos los horarios son UTC + 1 hora [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB GroupTraducción al español por Huan Manwë
Ejemplo de control de la cola de Impresión por programa WXP • esScripts... http://www.emesn.com/autoitforum/viewtopic.php?f=4&t=13&p=13&hili...
22 de 22 12/02/2012 12:00 a.m.
top related