Справочник по C#

    Исходники по языку программирования CSharp

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

    /
    /
    /
    42 Views


    /// 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

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

    0.00 (0%) 0 votes

    moyadcode13
    • Facebook
    • Twitter
    • Google+
    • Linkedin
    • Pinterest
    moyadcode10
    moyadcode11
    moyadcode9