Need help with Monitoring Printer Queue

rh37hd

Member
Joined
Apr 15, 2011
Messages
6
Programming Experience
Beginner
Hello,

I use the code from here: HOW TO: Determine Printer Status and Print Job Status from Visual Basic

It all works fine - I need to get the user name of the job. However, they are defined as longs, not strings.

I tried using the functions that came with the code, but I haven't had luck.
Basically when I do a msgbox(ji2(intCount).PrinterUserName I get a number
When I use PtrCtoVbString I get nothing
When I use GetString I get four square characters.

How can I return the user name (owner) of the print job?

Thanks.
 
Here is the VB.Net version of that article: How to call the EnumJobs function from a Visual Basic .NET application
The user from JOB_INFO_2 is a pointer to a string, from what I can see the article sample code includes several examples that show how to get the string.

An alternative is to use the WMI class Win32_PrintJob. Here is an example that similarily can be put in a Timer.Tick event handler:
VB.NET:
Dim builder As New System.Text.StringBuilder
For Each job As Win32.PrintJob In Win32.PrintJob.GetInstances
    builder.AppendFormat("{0} : {1}" & vbNewLine, job.Name, job.Owner)
Next
Me.Jobs.Text = builder.ToString
Win32.PrintJob is a strongly typed class generated from the WMI class, as explained in this thread WMI Code Creator
 
Back
Top