PrintJob(Win32_PrintJob)的TotalPages的实际数量 [英] Real number of TotalPages of a PrintJob (Win32_PrintJob)

查看:268
本文介绍了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_PrintJob)的TotalPages的实际数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆