There was a local printer in =>Control Panel\All Control Panel Items\Devices and Printers. and I deleted it manually by clicking "remove device". and the printer did get removed, not showing up anymore.
the question is, we have .net code below to check if a printer installed or not. it returns true. it seems the printer still exist if we do 'SELECT * FROM Win32_Printer' by name.
Questions:
1) can someone give me more details, why the local printer record still exists?
2) can I trust the code below, or maybe I need more conditions to check the printer installation?
ManagementScope oManagementScope = new ManagementScope(ManagementPath.DefaultPath);
oManagementScope.Connect();
SelectQuery oSelectQuery = new SelectQuery();
oSelectQuery.QueryString = @"SELECT * FROM Win32_Printer WHERE Name = '" + sPrinterName.Replace("\\", "\\\\") + "'";
using(ManagementObjectSearcher oObjectSearcher = new ManagementObjectSearcher(oManagementScope, oSelectQuery))
{
using(ManagementObjectCollection oObjectCollection = oObjectSearcher.Get())
{
return oObjectCollection.Count > 0;
}
}