Solved

WMI Pause, Resume & Cancel Printing in VB6

Posted on 2010-08-23
3
1,981 Views
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
0
Comment
Question by:thenemesiz
  • 2
3 Comments
 
LVL 6

Expert Comment

by:dax_bad
ID: 33499736
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

0
 
LVL 6

Accepted Solution

by:
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 

	objPrintJob.pause

	If checkSomething(test) = True Then
 		objPrintJob.Resume 
	Else
		objPrintJob.Cancel
	End if
Next

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

Set objWMIService = Nothing
Set colPrintJobs = Nothing 
Wscript.Quit

Open in new window

0
 

Author Comment

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

Appreciated!!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

773 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