Домой Printer Удаление принтера с помощью WMI: Справочник по C#

Удаление принтера с помощью WMI: Справочник по C#

899
0


/// name of the printer we want to remove/// 
public bool RemovePrinter(string name)
{
try
{
//use the ManagementScope class to connect to the local machine
ManagementScope scope = new ManagementScope(ManagementPath.DefaultPath);
scope.Connect();

//query Win32_Printer
SelectQuery query = new SelectQuery("select * from Win32_Printer");

ManagementObjectSearcher search = new ManagementObjectSearcher(scope, query);

//get all the printers for local machine
ManagementObjectCollection printers = search.Get();
foreach (ManagementObject printer in printers)
{
//get the name of the current printer in the list
string printerName = printer["Name"].ToString().ToLower();

//check for a match, if found then delete it or continue
//to the next printer in the list
if (printerName.Equals(name.ToLower()))
{
printer.Delete();
break;
}
else
continue;
}

return true;
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Error deleting printer: {0}", ex.Message));
return false;
}
}

Источник http://www.dreamincode.net

ЧИТАТЬ ТАКЖЕ:  Создание локальных пользователей: Справочник по C#

Удаление принтера с помощью WMI: Справочник по C#

0.00 (0%) 0 votes

ОСТАВЬТЕ ОТВЕТ

Пожалуйста, введите ваш комментарий!
пожалуйста, введите ваше имя здесь