(C#) ---> How to Get Real Number of Copies from a doc sent to printer?

5 views
Skip to first unread message

vitor...@gmail.com

unread,
May 5, 2018, 7:34:30 PM5/5/18
to
My task is very simple, but I cannot do that with WMI. So I thought I could get some info using WMI and than adding some pinvoke to get the copies. I don't have a real printer to test printed pages, so my point is the number of jobs in print queue, name of printer, name of submitter (Owner), name of document, total pages and copies by doc.
Here is some code that I was trying:
------------------------------------
//Devolve uma lista com todas as impressoras instaladas localmente na máquina
foreach (string printer in PrinterSettings.InstalledPrinters)
{

if (!printer.Equals(null))
{
//preenchendo listBoxImpressoras com nomes de impressoras
listBoxImpressoras.Items.Add(printer);
}
else
{
listBoxImpressoras.Items.Add("Não há impressoras instaladas nesta máquina!");
MessageBox.Show("Instale o driver da impressora em questão ou verifique se há \n problema com o driver.");
}

}
----------------------------
Of course this piece of code don't have WMI, but I will use something like this one:
----------------------------
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PrintJob WHERE Name ='"+docName+"'");

foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_PrintJob instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Document: {0}", queryObj["Document"]);
}
------------------------------
So I have 3 listBox to populate. One goes printer's name, another goes doc's name and last one goes details about each job.
------------------------------
Can someone help? Thank you so much and God may bless you a lot.
Reply all
Reply to author
Forward
0 new messages