heydude
asked on
help with print job monitor
I'm trying to create a program that when I run it I can capture a print jobs name,total pages, owner, etc.. I'm trying to use wmi win32_printjob for this, but I just can't seem to get it. I would like to be able to capture the info into variables so that I can write them to a file, database, etc... I found the below code and it works, I just can't figure out how to get it not to return so much info, just return the fields I want and how to get the info into variables for each property. Looking to get this working in vb.net
Thank you
Public Class Form1
WithEvents watcher As ManagementEventWatcher
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormC losedEvent Args) _
Handles Me.FormClosed
watcher.Stop()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim q As New WqlEventQuery("__InstanceC reationEve nt")
q.WithinInterval = New TimeSpan(0, 0, 1)
q.Condition = "TargetInstance ISA 'Win32_PrintJob'"
watcher = New ManagementEventWatcher(q)
watcher.Start()
End Sub
Private Sub watcher_EventArrived(ByVal sender As Object, ByVal e As System.Management.EventArr ivedEventA rgs) _
Handles watcher.EventArrived
Dim printjob As ManagementBaseObject = e.NewEvent.Item("TargetIns tance")
Dim sb As New System.Text.StringBuilder
sb.AppendLine("This printjob just started:")
For Each p As PropertyData In printjob.Properties
p.Name
sb.AppendFormat("{0}: {1}", p.Name, p.Value)
sb.AppendLine()
Next
MsgBox(sb.ToString)
End Sub
End Class
Thank you
Public Class Form1
WithEvents watcher As ManagementEventWatcher
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormC
Handles Me.FormClosed
watcher.Stop()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim q As New WqlEventQuery("__InstanceC
q.WithinInterval = New TimeSpan(0, 0, 1)
q.Condition = "TargetInstance ISA 'Win32_PrintJob'"
watcher = New ManagementEventWatcher(q)
watcher.Start()
End Sub
Private Sub watcher_EventArrived(ByVal
Handles watcher.EventArrived
Dim printjob As ManagementBaseObject = e.NewEvent.Item("TargetIns
Dim sb As New System.Text.StringBuilder
sb.AppendLine("This printjob just started:")
For Each p As PropertyData In printjob.Properties
p.Name
sb.AppendFormat("{0}: {1}", p.Name, p.Value)
sb.AppendLine()
Next
MsgBox(sb.ToString)
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I did end up coming up with a way to do it. I'm going to give you the points because I can probably use the code above for something.
ASKER