WMI Pause, Resume & Cancel Printing in VB6

Posted on 2010-08-23
Last Modified: 2013-12-20
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
Question by:thenemesiz
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 33499736
If you now how to write VBscripts, here's a few code snippets that will help you with Printers:

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

Open in new window


Accepted Solution

dax_bad earned 500 total points
ID: 33499779
Or something like this?
strComputer = "."	replace . with dns name or IP of print server or leave if script is running on the print server

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs =  objWMIService.ExecQuery _
    ("Select * from Win32_PrintJob")

For Each objPrintJob in colPrintJobs 


	If checkSomething(test) = True Then
	End if

Function checkSomething(ByVal test)
'check something
If test.something = someValue Then
	checkPrintJob = True
	checkPrintJob = False
End Function

Set objWMIService = Nothing
Set colPrintJobs = Nothing 

Open in new window


Author Comment

ID: 33500219
that's extremely helpful 'dax bad'


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question