I have the following code:
private void btnDeletar_Click(object sender, RoutedEventArgs e)
{
string nomeImpressora = null;
if(cmbImpressoras.SelectedIndex != -1)
nomeImpressora = cmbImpressoras.SelectedItem.ToString();
else
MessageBox.Show("Selecione uma Impressora");
ManagementScope scope = new ManagementScope(ManagementPath.DefaultPath);
scope.Connect();
SelectQuery query = new SelectQuery("select * from Win32_Printer");
ManagementObjectSearcher search = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection printers = search.Get();
foreach (ManagementObject printer in printers)
{
string printerName = printer["Name"].ToString().ToLower();
if (printerName.Equals(nomeImpressora.ToLower()))
{
try
{
DriverImpressora(printer["DriverName"].ToString());
printer.Delete();
}
catch (Exception)
{
MessageBox.Show("Impossível remover impressora!");
}
break;
}
}
}
Now the doubt:
I think the printer is only removed, but the drive does not, if it does not remove the drive, using the Win32_PrinterDriver class is it possible to remove?