I am able to get print job informations from Win32_PrintJob
by using WMI and ManagementEventWatcher
but I cannot seem to find the printer name. I also looked to this Win32_PrintJob documentation and the closest thing to printer name is DriverName
property, but it is the printer driver name, not the printer name as displayed in the Control Panel's Devices and Printers.
So, as stated in the title, how can I get the printer name from print job from Win32_PrintJob
?
This is my partial codes so far to get the print job:
public void PrintHelperInstance_OnPrintJobChange(object sender, EventArrivedEventArgs e)
{
ManagementBaseObject objProps = (ManagementBaseObject)e.NewEvent.Properties["TargetInstance"].Value;
string jobName = objProps["Document"].ToString();
if (jobName == "Test Print Form")
{
if (!IsFoundPrintJob)
{
IsFoundPrintJob = true;
}
CurrentJobStatus = (string)objProps["JobStatus"];
if (CurrentJobStatus != PreviousJobStatus)
{
uint jobId = (uint)objProps["JobId"];
string jobPrinter = (string)objProps["DriverName"];
string jobHost = (string)objProps["HostPrintQueue"];
string jobStatus = (string)objProps["JobStatus"];
PreviousJobStatus = CurrentJobStatus;
}
}
}