How to pause the Win32_printJob by Printername and JobID

后端 未结 2 1350
别跟我提以往
别跟我提以往 2020-12-20 07:15

TASK

When user print the document ,pause the pop will appear then fill the form click enter the form will closed and job has been r

相关标签:
2条回答
  • 2020-12-20 07:23

    WMI is too slow for this. You probably need to use FindFirstPrinterChangeNotification and FindNextPrinterChangeNotification.

    You might find these examples useful.

    0 讨论(0)
  • 2020-12-20 07:45

    Finally, I've found a solution on MSDN official documentation website for controlling printer, here is the link: https://www.codeproject.com/Articles/6592/A-Simple-Approach-for-Controlling-Print-Jobs-using

    It shows that how to Pause, Resume and Delete a print job. The core class is Win32_PrintJob. The variable of printJob is from ManagementObjectSearcher object which searched one printer instance.

    printJob.InvokeMethod("Pause", null);
    printJob.InvokeMethod("Resume", null);
    printJob.Delete()
    

    I still found that its Python implementation of code : http://timgolden.me.uk/python/wmi/cookbook.html#watch-for-new-print-jobs

    import wmi
    c = wmi.WMI ()
    
    print_job_watcher = c.Win32_PrintJob.watch_for (
      notification_type="Creation",
      delay_secs=1
    )
    
    while 1:
      pj = print_job_watcher ()
      print "User %s has submitted %d pages to printer %s" % \
        (pj.Owner, pj.TotalPages, pj.Name)
    
    0 讨论(0)
提交回复
热议问题