Get printer status before sending a job with C#
I've an application the needs to query the state of a printer before attempting to send it anything.if catch error out of paper or low paper and etc i can detect them.
but following code always return result to Ready when printer is no paper.
oManagementScope = new ManagementScope(ManagementPath.DefaultPath);
oManagementScope.Connect();
string sPrinterName = comboBox1.SelectedItem.ToString();
SelectQuery oSelectQuery = new SelectQuery();
oSelectQuery.QueryString = @"SELECT * FROM Win32_Printer WHERE Name = '" +
sPrinterName.Replace("\\", "\\\\") + "'";
ManagementObjectSearcher oObjectSearcher =new ManagementObjectSearcher(oManagementScope, oSelectQuery);
ManagementObjectCollection oObjectCollection = oObjectSearcher.Get();
foreach (ManagementObject MObj in oObjectCollection)
{
string myString = MObj["PrinterStatus"].ToString();
Int32 dStatus = Convert.ToInt32(myString);
label1.Text = printerStatus[dStatus];
}
thanks