Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Print Jobs status using WMI C#

1,405 views
Skip to first unread message

SiPearson

unread,
Apr 23, 2003, 11:47:27 AM4/23/03
to
Hi,

I'm trying to get information about all the print jobs on a certain
printer on a certain server. The attached code will return the jobs
for all printers on a server, it seems the RelativePath property is
being ignored!

I'd be grateful if anyone could help as its driving me MAD.

ta

Si

--------------

static void JobsOnPrinter()
{
ManagementPath manPath = new ManagementPath();
manPath.NamespacePath = @"root\CIMV2";
manPath.Server = "Server";
manPath.RelativePath = "Win32_Printer.DeviceID='Printer'";

ManagementScope manScope = new ManagementScope(manPath);

System.Management.ObjectQuery printQuery = new
System.Management.ObjectQuery("SELECT * FROM Win32_PrintJob");

ManagementObjectSearcher printSearch = new
ManagementObjectSearcher(manScope, printQuery);
ManagementObjectCollection printCollection = printSearch.Get();

foreach( ManagementObject job in printCollection )
{
Console.WriteLine("===========================================");
Console.WriteLine("Printer : " + job["Name"].ToString());
Console.WriteLine("Doc : " + job["Document"].ToString());
Console.WriteLine("Status : " + job["StatusMask"].ToString());
}
}

Jian-Shen Lin[MS]

unread,
Apr 24, 2003, 9:17:55 PM4/24/03
to

The constructor you use is not supported:
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemmanagementmana
gementpathclassctortopic.asp?frame=true

We use instead
ManagementScope manScope = new ManagementScope(manPath.RelativePath);


Thanks

Jian Shen

This posting is provided "AS IS" with no warranties, and confers no rights.

Andy Cheung [MSFT]

unread,
Apr 27, 2003, 2:40:20 PM4/27/03
to
A ManagementScope object represents an anchor to a WMI namespace on a machine. When a ManagementPath object is used in a ManagementScope(ManagementPath) constructor, only the Server property and the NamespacePath property are used to construct the ManagementScope object. The RelativePath property is not involved in the intialization of the ManagementScope object.
 
You probably need to specify a more specialized WQL query to query the print jobs for a certain printer on a server. It seems you can use Win32_PrintJob.Name property to identify which printer the job is associated to. e.g.
SELECT * FROM Win32_PrintJob WHERE Name LIKE "%MyPrinter Name%"

--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
 
"Jian-Shen Lin[MS]" <js...@online.microsoft.com> wrote in message news:OFBPJisC...@cpmsftngxa06.phx.gbl...

Si

unread,
Apr 28, 2003, 4:47:30 AM4/28/03
to

Thanks for replying Jian.

I tried this,

string relPath =
@"\\ps\root\CIMV2:Win32_Printer.DeviceID='TP2'";
ManagementScope manScope = new ManagementScope(relPath);

which produced the same results as before. I guess what
Andy says in his reply is correct and RelativePath is not
involved.

thanks again

Simon

Si

unread,
Apr 28, 2003, 4:59:22 AM4/28/03
to
Thanks for replying Andy, unfortunatly I cannot use LIKE
(which I had already tried), as we're running 2000 not xp.

Any other suggestions would be greatly accepted, otherwise
I'll go back to using ads.

Thanks
Si

Dan

unread,
Apr 28, 2003, 4:18:54 PM4/28/03
to
Can someone please tell me the equivalent of the following in VB.NET

> string relPath =
> @"\\ps\root\CIMV2:Win32_Printer.DeviceID='TP2'";


I am unable to translate it to VB.NET

Thanks a lot

Scott

unread,
Apr 29, 2003, 2:38:11 PM4/29/03
to
Simon, did you ever get this to work? I would love to see the full source if you
did. Thanks

Scott

In article <013701c30d62$cd66ac40$3301...@phx.gbl>, "Si" says...

Andy Cheung [MSFT]

unread,
Apr 30, 2003, 2:56:09 PM4/30/03
to
Unfortunately the Win32_PrintJob.Name property appears to be a concatention of a printer name and a job id, so you need to use LIKE in the WQL query if you want to let WMI do the filtering. The workaround is to enumerate all instances of the Win32_PrintJob class, and do the filtering in your code by checking if the Name property value contains the printer name.

--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
 

Andy Cheung [MSFT]

unread,
Apr 30, 2003, 2:59:43 PM4/30/03
to

--
Andy Cheung
Microsoft WMI Test Engineer
This posting is provided "As Is" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
 
0 new messages