1
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 only the printer is removed, but the drive is not, if you do not remove the drive, using the Win32_printerdriver class you can remove?
Thanks, already gave me a good way, I edited the question and put the code I’m using to remove, but is giving an error Generic Failure.
– MeuChapeu
Editing is usually done when you go better at the same question by adding information that helps with that question. If you are going to ask another question you should not use the edit if not the answers given become invalid.
– Maniero
Okay, I’m back to the original question!
– MeuChapeu