Change the default printer in a WPF application

I am looking for the best way to change the default printer in a WPF application. Here are the steps we hope the application can do.

  • Select a location from the drop-down list that maps to the printer name.
  • Change the default printer to display name.
  • Launch IE and specify the SSRS report.
  • Then the user will print a report from IE, which will use the new printer by default.

Step two is what I'm looking for.

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

Thanks!

+4
source share
1 answer

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 }); } } 
+6
source

All Articles