How to pause the Win32_printJob by Printername and JobID

白昼怎懂夜的黑 提交于 2019-11-29 12:27:29

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

You might find these examples useful.

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!