"Generic failure" from ExecNotificationQuery
Hi. This question is with VBScript rather than VB, but it isn't web related. If there is a better place for me to post this, please let me know. :)
To give some context:
I work in a computer lab and one of my jobs is to stare at a printing queue, making sure that nothing bigger than 20 pages or so goes through without at least checking it out. This is kind of brain dead and repetitive, so I figured there must be some way to automatically pause big jobs and create a dialog box to alert me when such a job came in. After googling a bit, it seemed as though the easiest way to go about this was to use VBScript + WSH + WMI. That seemed cool enough, since learning new stuff never hurts.
I think the code below ought to listen for new print jobs and then echo a the textual representation of each new job.
It doesn't get that far, sadly. The ExecNotificationQuery call fails, and the script ends up generating the following output:
I have no clue how to debug further from here. Any thoughts?
Also, does anyone have any suggestions for decent non-MS sites or books as supplemental references?
To give some context:
I work in a computer lab and one of my jobs is to stare at a printing queue, making sure that nothing bigger than 20 pages or so goes through without at least checking it out. This is kind of brain dead and repetitive, so I figured there must be some way to automatically pause big jobs and create a dialog box to alert me when such a job came in. After googling a bit, it seemed as though the easiest way to go about this was to use VBScript + WSH + WMI. That seemed cool enough, since learning new stuff never hurts.
I think the code below ought to listen for new print jobs and then echo a the textual representation of each new job.
Option Explicit
On Error Resume Next
Dim strComputer
strComputer = "."
' creates SWbemServices object.
Dim objWMIService
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Dim objNewJobs
Set objNewJobs = objWMIService.ExecNotificationQuery ( _
"Select * from __InstanceCreationEvent " & _
"WITHIN 10 " & _
"WHERE TargetInstance ISA 'Win32_PrintJob' " )
If Err <> 0 Then
Wscript.Echo Err.Number & VbTab & Err.Description
WScript.Quit
End If
Do While 1
Dim objNewJob
Set objNewJob = objNewJobs.NextEvent()
WScript.Echo( objNewJob.GetObjectText_ )
Loop
It doesn't get that far, sadly. The ExecNotificationQuery call fails, and the script ends up generating the following output:
C:\Documents and Settings\cmeyers\Desktop>cscript file.vbs Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. -2147217407 Generic failure
I have no clue how to debug further from here. Any thoughts?
Also, does anyone have any suggestions for decent non-MS sites or books as supplemental references?
