我想使用Python清除或删除打印作业。
但是我怎样才能获得JobID
?
win32print.SetJob(hPrinter, JobID , Level , JobInfo , Command)
我怎么能运行这段代码?
jobs = []
for p in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL,None, 1):
flags, desc, name, comment = p
pHandle = win32print.OpenPrinter(name)
print = list(win32print.EnumJobs(pHandle, 0, -1, 1))
jobs.extend(print)
SetJob(pHandle, id, 1,JOB_CONTROL_DELETE)
#where should i get id from?
win32print.ClosePrinter(pHandle)
答案 0 :(得分:0)
从您的代码开始,我设法创建了一个小脚本,删除任何(本地)打印机上的任何打印作业(我已经测试过它,正常工作)。
这是(我用 Py35 运行它):
import win32print
if __name__ == "__main__":
printer_info_level = 1
for printer_info in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL, None, printer_info_level):
name = printer_info[2]
#print(printer_info)
printer_handle = win32print.OpenPrinter(name)
job_info_level = 1
job_info_tuple = win32print.EnumJobs(printer_handle, 0, -1, job_info_level)
#print(type(job_info_tuple), len(job_info_tuple))
for job_info in job_info_tuple:
#print("\t", type(job_info), job_info, dir(job_info))
win32print.SetJob(printer_handle, job_info["JobId"], job_info_level, job_info, win32print.JOB_CONTROL_DELETE)
win32print.ClosePrinter(printer_handle)
备注强>:
EnumJobs
返回字典的元组(其中每个字典包含[MSDN]: JOB_INFO_1
structure - job_info_level = 1
),或(显然)如果打印机没有排队作业,则为空元组EnumJobs
的信息如何传递给SetJob
:
JobID
参数(您询问的内容)是job_info["JobId"]
(查看上一张子弹)Level
和JobInfo