Skip to content
Advertisement

How can I use SetJob in win32print?

I want to clear or delete print jobs using Python. But how can I get JobID?

win32print.SetJob(hPrinter, JobID , Level , JobInfo , Command)

How could I run this code?

JavaScript

Advertisement

Answer

Starting from your code, I’ve managed to create a small script that deletes any print job on any (local) printer (I’ve tested it and it works).

Here it is (I’ve run it with Python 3.5):

code00.py:

JavaScript

Notes:

  • What I said in my comment (about iterating over printers) still stands, but I suppose that is beyond the scope of this question

  • I’ve improved the script a little bit:

    • Give (more) meaningful names to variables

    • Use variables instead of plain numbers to increase code readability

    • Other small corrections

    • Probably, it could use some exception handling

  • The secret of the script consist of:

    • EnumJobs returning a tuple of dictionaries (where each dictionary wraps an [MS.Docs]: JOB_INFO_1 structure – for job_info_level = 1), or (obviously) an empty tuple if there are no queued jobs for the printer
  • How the information from EnumJobs is passed to SetJob:

    • The JobID argument (that you asked about) is job_info["JobId"] (check previous bullet)

    • Also notice the next 2 arguments: Level and JobInfo

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement