Link to home
Start Free TrialLog in
Avatar of thenemesiz
thenemesizFlag for Kenya

asked on

WMI Pause, Resume & Cancel Printing in VB6

I would like to use VB6 to:

- Monitor default printer
- Pause any print job
- Run a sub
- If sub returns true then resume printing
- If not the cancel the print job

The default printer is a receipt printer that doesn't print any other documents.

I have successfully identified the default printer using WMI and can call the printer by a sub:

Dim objPrinter As Printer

Set objPrinter = GetDefaultPrinter()
MsgBox "Default printer is: " + objPrinter.DeviceName
MsgBox "Driver name is: " + objPrinter.DriverName
MsgBox "Port is: " + objPrinter.Port
Set objPrinter = Nothing

Can someone please help me pause any jobs on the printer till the above steps are followed

Thanks a Billion
Avatar of dax_bad
dax_bad
Flag of Denmark image

If you now how to write VBscripts, here's a few code snippets that will help you with Printers:
http://www.activxperts.com/activmonitor/windowsmanagement/adminscripts/printing/servers/#PausePrintJobs.htm



strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs =  objWMIService.ExecQuery _
    ("Select * from Win32_PrintJob")
For Each objPrintJob in colPrintJobs 
    objPrintJob.Pause    'Pauses All jobs in the collection
    objPrintJob.Resume    'Resumes all jobs in the collection
Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dax_bad
dax_bad
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thenemesiz

ASKER

that's extremely helpful 'dax bad'

Appreciated!!