Link to home
Start Free TrialLog in
Avatar of heydude
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.FormClosedEventArgs) _
    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("__InstanceCreationEvent")
        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.EventArrivedEventArgs) _
    Handles watcher.EventArrived
        Dim printjob As ManagementBaseObject = e.NewEvent.Item("TargetInstance")
        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
Avatar of theGhost_k8
theGhost_k8
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of heydude
heydude

ASKER

didn't really help me?
Avatar of heydude

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.