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

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

621
0


/// 
/// method to set a specified printer as the system's default printer
/// 
/// name of the printer we want to be default/// Returns true if successfull
/// Throws exception if printer not installed
public bool SetPrinterToDefault(string printer)
{
//path we need for WMI
string queryPath = "win32_printer.DeviceId='" + printer + "'";

try
{
//ManagementObject for doing the retrieval
ManagementObject managementObj = new ManagementObject(queryPath);

//ManagementBaseObject which will hold the results of InvokeMethod
ManagementBaseObject obj = managementObj.InvokeMethod("SetDefaultPrinter", null, null);

//if we're null the something went wrong
if (obj == null)
throw new Exception("Unable to set default printer.");

//now get the return value and make our decision based on that
int result = (int)obj.Properties["ReturnValue"].Value;

if (result == 0)
return true;
else
return false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
}

Взято с http://www.dreamincode.net

ЧИТАТЬ ТАКЖЕ:  Удаляем принтер через WMI: Справочник по C#

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

0.00 (0%) 0 votes

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

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