Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

help with print job monitor

Posted on 2007-03-27
3
Medium Priority
?
2,052 Views
Last Modified: 2013-11-07
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
0
Comment
Question by:heydude
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
K V earned 1000 total points
ID: 18805958
this guy helped me and hence it will work for u too : http://www.experts-exchange.com/M_38421.html

bob said:
I have this WMI class that retrieves PrintJob information, but I can't test it right now:

' Add a reference to System.Management.dll.

Imports System.Management

Namespace My.Computer.WMI

  Public Class PrintJob

    Public DataType As String
    Public Description As String
    Public Document As String
    Public DriverName As String
    Public ElapsedTime As Date
    Public HostPrintQueue As String
    Public InstallDate As Date
    Public JobId As Integer    'uint32
    Public JobStatus As String
    Public Notify As String
    Public Owner As String
    Public PagesPrinted As Integer     'uint32
    Public Parameters As String
    Public PrintProcessor As String
    Public Priority As Integer     'uint32
    Public Size As Integer     'uint32
    Public StartTime As Date
    Public Status As String
    Public StatusMask As Integer     'uint32
    Public TimeSubmitted As Date
    Public TotalPages As Integer     'uint32
    Public UntilTime As Date


    Public Shared ReadOnly Property List() As PrintJob()
      Get
        Dim query As String = "Select * From Win32_PrintJob"

        Dim searcher As New ManagementObjectSearcher(query)

        Dim results As ManagementObjectCollection = searcher.Get

        Dim listPrintJobs(results.Count - 1) As PrintJob

        Dim index As Integer = 0

        For Each entryCurrent As ManagementObject In results

          Dim job As New PrintJob

          job.DataType = entryCurrent("DataType")
          job.Description = entryCurrent("Description")
          job.Document = entryCurrent("Document")
          job.DriverName = entryCurrent("DriverName")
          job.ElapsedTime = entryCurrent("ElapsedTime")
          job.HostPrintQueue = entryCurrent("HostPrintQueue")
          job.InstallDate = entryCurrent("InstallDate")
          job.JobId = entryCurrent("JobId")
          job.JobStatus = entryCurrent("JobStatus")
          job.Notify = entryCurrent("Notify")
          job.Owner = entryCurrent("Owner")
          job.PagesPrinted = Convert.ToInt32(entryCurrent("PagesPrinted"))
          job.Parameters = entryCurrent("Parameters")
          job.PrintProcessor = entryCurrent("PrintProcessor")
          job.Priority = entryCurrent("Priority")
          job.Size = entryCurrent("Size")
          job.StartTime = entryCurrent("StartTime")
          job.Status = entryCurrent("Status")
          job.StatusMask = entryCurrent("StatusMask")
          job.TimeSubmitted = entryCurrent("TimeSubmitted")
          job.TotalPages = Convert.ToInt32(entryCurrent("TotalPages"))
          job.UntilTime = entryCurrent("UntilTime")

          listPrintJobs(index) = job

          index += 1

        Next entryCurrent

        Return listPrintJobs
      End Get
    End Property    'List

  End Class

End Namespace

Sample usage:
  Public Shared Function PrintJobs() As String

    Dim builder As New StringBuilder
    Dim list As PrintJob() = PrintJob.List()

    If list.Length = 0 Then
      builder.Append("(None)")
    Else
      For Each job As PrintJob In list
        builder.Append(job.Document & Environment.NewLine)
      Next
    End If

    Return builder.ToString()

  End Function
0
 

Author Comment

by:heydude
ID: 18808485
didn't really help me?
0
 

Author Comment

by:heydude
ID: 18833873
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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

610 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