PrintJob(Win32

编程入门 行业动态 更新时间:2024-10-20 16:19:10
本文介绍了PrintJob(Win32_PrintJob)的TotalPages的实际数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

每当ManagementEventWatcher发生更改时,我都在查询Win32_PrintJob WMI类,我获取了有关它的数据,例如:Document,HostPrintQueue,JobId,JobStatus,TotalPages等.实际要打印的页面数,目前似乎仍要获取这些数据,但打印作业仍未完成处理,并转移了当时要打印的页面数,但实际总数是其他数量,如何获取完成处理时打印作业的真实数量? 这是我的代码:

I'm querying to Win32_PrintJob WMI class every time there is a change with ManagementEventWatcher, I obtained data about it, such as: Document, HostPrintQueue, JobId, JobStatus, TotalPages, etc. But TotalPages is not representing the real number of page to print, Seems at the moment to obtain these data still the printjob doesn't finished to process and devolving a number of pages to print in that moment but the real total is other number, How to get the real number of a print job when finished it to process? Here is my code:

ManagementEventWatcher createPrintJobWatcher; String strComputerName = "."; // Create event query to be notified within 1 milli second of a change in a service WqlEventQuery createPrintJobQuery = new WqlEventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 0.001 WHERE TargetInstance ISA \"Win32_PrintJob\""); createPrintJobWatcher = new ManagementEventWatcher(); createPrintJobWatcher.Scope = new ManagementScope("\\\\" + strComputerName + "\\root\\CIMV2"); createPrintJobWatcher.Query = createPrintJobQuery; // times out watcher.WaitForNextEvent in 1 seconds createPrintJobWatcher.Options.Timeout = new TimeSpan(0, 0, 1); //set the print event handler createPrintJobWatcher.EventArrived += new EventArrivedEventHandler(createPrintJobListener); createPrintJobWatcher.Start(); Console.WriteLine("Listening..."); Console.ReadLine();

createPrintJobListener方法:

createPrintJobListener method:

static void createPrintJobListener(object sender, EventArrivedEventArgs e) { SelectQuery query = new SelectQuery("Win32_PrintJob"); using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) using (ManagementObjectCollection printJobs = searcher.Get()) foreach (ManagementObject printJob in printJobs) { Console.WriteLine("c1:", printJob); Console.WriteLine("ID: {0}", printJob.GetPropertyValue("JobId").ToString()); Console.WriteLine("name: {0}", printJob.GetPropertyValue("name").ToString()); Console.WriteLine("status: {0}", printJob.GetPropertyValue("status").ToString()); if (printJob.GetPropertyValue("JobStatus") != null) { Console.WriteLine("JobStatus: {0}", printJob.GetPropertyValue("JobStatus").ToString()); } else { Console.WriteLine("JobStatus: NULLLLLL"); } Console.WriteLine("PC: {0}", printJob.GetPropertyValue("HostPrintQueue").ToString()); Console.WriteLine("TOTOAL PAGES: {0}", printJob.GetPropertyValue("TotalPages").ToString()); } }

推荐答案

WMI可能不足以做到这一点.

Windows无法可靠地提供页数(或副本等),因此获取准确信息的唯一方法是暂停作业并对其进行解析.这是一项艰巨的任务,但这里有更多信息.

Windows doesn't reliably provide the page count (or copies etc), so the only way to get accurate info is to pause the job and parse it. This is a non-trivial task, but here's a little more info.

更多推荐

PrintJob(Win32

本文发布于:2023-11-06 06:43:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PrintJob

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!