开发者

Change Default Printer within WPF Application

开发者 https://www.devze.com 2023-03-13 21:50 出处:网络
I\'m looking for the best approach to change the default printer within a WPF application. Here are the steps the we\'re ho开发者_如何学编程ping the application can do.

I'm looking for the best approach to change the default printer within a WPF application. Here are the steps the we're ho开发者_如何学编程ping the application can do.

  1. Select a location from a drop down which is mapped to a printer name.
  2. Change the default printer to the mapped name.
  3. Launch IE and point to SSRS report.
  4. User will then print report from IE, which will use the new default printer

Step two is what I'm looking for assistance with.

Is this a use case for WMI? If so, any resources on the subject would be a huge help.

Thanks!


use this:

var query = new ManagementObjectSearcher("SELECT * FROM Win32_Printer"); 
var printers = query.Get();
string printerName = "Printer to set as default" ;
foreach(ManagementObject printer in printers) 
{ 
   if (printer["name"].ToString() == printerName.ToString()) 
   { 
      printer.InvokeMethod("SetDefaultPrinter", new object[] { printerName }); 
   } 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消