I write a VBS to monitor print job.

The following script works well.
##############VBS-1####################
Set colPrintJobs = objWMIService.ExecQuery("Select * from Win32_PrintJob")

For each objPrintJob in colPrintJobs
Wscript.echo objPrintJob.caption
next
#########################################

But when I use ExecNotificationQuery to retrieve the object collection,it
throws out a running time error which tells me that object does not support
the property or method :"objPrintJob.caption".Could you tell how to monitor
print job?

##############VBS-2####################
Set colPrintJobs = objWMIService.ExecNotificationQuery("Select * from
__instancecreationevent WITHIN 1 WHERE TargetInstance ISA 'Win32_PrintJob'")

Do While True
Set objPrintJob =colPrintJobs.NextEvent()
WScript.Echo "Caption: " & objPrintJob.Caption
Loop
#########################################

RE: How to monitor print job by urkec

urkec
Wed Mar 19 11:32:00 CDT 2008

"£¤£¤£¤" wrote:

> I write a VBS to monitor print job.
>
> The following script works well.
> ##############VBS-1####################
> Set colPrintJobs = objWMIService.ExecQuery("Select * from Win32_PrintJob")
>
> For each objPrintJob in colPrintJobs
> Wscript.echo objPrintJob.caption
> next
> #########################################
>
> But when I use ExecNotificationQuery to retrieve the object collection,it
> throws out a running time error which tells me that object does not support
> the property or method :"objPrintJob.caption".Could you tell how to monitor
> print job?
>
> ##############VBS-2####################
> Set colPrintJobs = objWMIService.ExecNotificationQuery("Select * from
> __instancecreationevent WITHIN 1 WHERE TargetInstance ISA 'Win32_PrintJob'")
>
> Do While True
> Set objPrintJob =colPrintJobs.NextEvent()
> WScript.Echo "Caption: " & objPrintJob.Caption
> Loop
> #########################################
>
>
>

This is because NextEvent returns an instance of __InstanceCreationEvent
class, so you have to use it's TargetInstance property to get the
Win32_PrintJob instance:

Set objWMIService = GetObject _
("winmgmts:root\cimv2")

Set colPrintJobs = objWMIService.ExecNotificationQuery _
("Select * from __instancecreationevent WITHIN 1 " & _
"WHERE TargetInstance ISA 'Win32_PrintJob'")

Do While True
Set objPrintJob =colPrintJobs.NextEvent()
WScript.Echo "Caption: " & _
objPrintJob.TargetInstance.Caption
Loop

--
urkec

Re: How to monitor print job by £¤£¤£¤

£¤£¤£¤
Fri Mar 21 18:10:24 CDT 2008

Thanks! I see.