I am able to get the list of network printers via this code:
private void Form1_Load(object sender, EventArgs e)
{
foreach (String printer in PrinterSettings.InstalledPrinters)
{
listBox1.Items.Add(printer.ToString());
}
}
For each network printer, I want to extract out more information like:
(a) get document information, like number of pages printed, file names, file sizes, etc.
(b) get computer IP address from which document was printed.
(c) get username of who printed the document.
How do I achieve the above? any code samples would be appreciated. Do I have to look into Windows Management Instrumentation(WMI) stuffs?

4 answers
at first network printers have to be installed on local pc or have to be sharded, in order for your program be able to see it.
You can use printer interigation via c# code and get basic informations.
For detail information i have not find solution via c# and had to use WMI in order to get informations about each print job.
Tomorow if you do not find solution i will send you script example for print interigation.
winodws prining hold information about job:
what is print queue, who was the user that send, job name, time etc.
as promissed:
hope this helps
answered one year ago by:
556
see answer that i have edited above :)
answered one year ago by:
556
I copy your code and save it in test1.cs.
At the Visual Studio 2008 Command Prompt, when I compile, I have a list of errors as below:
>csc test.1cs
test1.cs(9,8): error CS1518: Expected class, delegate, enum, interface, or struct
test1.cs(9,25): error CS1001: Identifier expected
test1.cs(9,27): error CS1518: Expected class, delegate, enum, interface, or struct
test1.cs(12,28): error CS1518: Expected class, delegate, enum, interface, or struct
test1.cs(15,1): error CS1022: Type or namespace definition, or end-of-file expected
Also, have you looked into PrinterQueueWatch.NET from http://www.merrioncomputing.com ?
also http://puma.codeplex.com/ has a very useful application, but their code is in VB.NET, what I want is in C#.NET.
answered one year ago by:
494
556
no i cannot say that i had looked on any others. I like to do things my way for reason of knowledge. The code that i shared is not completed code as mine has loads more to it and this was extract for functionality purpose. i would recomend to go through my code and see what it does.
556
just wondering if you have loaded all references lets see: microsoft csharp system system.core system.data system.data.datasetextensions system.management -> important system.printing -> important but vs2008 will highliht parts for which you need to load the libs.
yes, agree that it is easier to build up code ourselves, rather than rely on complete products.
My below code works when the Form loads and I can get a list of Network Printers in listBox1.
I am also able to see a specific printer's property name and value in listBox2.
private void Form1_Load(object sender, EventArgs e)
{
foreach (String printer in PrinterSettings.InstalledPrinters)
{
listBox1.Items.Add(printer.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
string printerName = "Ricoh-L4-1";
string query = string.Format("SELECT * from Win32_Printer WHERE Name LIKE '%{0}'", printerName);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection coll = searcher.Get();
foreach (ManagementObject printer in coll)
{
foreach (PropertyData property in printer.Properties)
{
listBox2.Items.Add(string.Format("{0}: {1}", property.Name, property.Value));
}
}
}
But when I try to find JobId, Owner, TotalPages for a particular printer (when I actually send jobs to print to that printer), those values do not display at all.
private void button2_Click(object sender, EventArgs e)
{
listBox2.Items.Clear();
string printerName = "Ricoh-L4-1";
string query = string.Format("SELECT * from Win32_PrintJob WHERE Name LIKE '%{0}'", printerName);
ManagementObjectSearcher SearchPrintJobs = new ManagementObjectSearcher(query);
ManagementObjectCollection PrntJobCollection = SearchPrintJobs.Get();
foreach (ManagementObject PrntJob in PrntJobCollection)
{
string m_JobID = PrntJob.Properties["JobId"].Value.ToString();
string m_Owner = PrntJob.Properties["Owner"].Value.ToString();
string m_TotalPages = PrntJob.Properties["TotalPages"].Value.ToString();
listBox2.Items.Add(string.Format("{0}:{1}:{2}", m_JobID,m_Owner,m_TotalPages));
}
}
Do you have any idea how to get above to work? thanks in advance.
answered one year ago by:
494
556
As you know when job is send to printer it behaves like this: job is moved as print job over to printque(flattening image and so on) and after it is moved it is spooling rightaway to printer (depend on your settings. So to avoid problem you have few options: 1, Pause print queue while script is running. all jobs will be there. Release every so often (so your script will be able to pick the job up. 2, For this solution, i would create temp queue, where all jobs are held and after script finish with them, it is moved to printer. 3, integrate it with windows printing but there i have no idea how to do that. sorry cannot help any more