Reputation: 2847
I'm looking for the best approach to change the default printer within a WPF application. Here are the steps the we're hoping the application can do.
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!
Upvotes: 4
Views: 2915
Reputation: 7968
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 });
}
}
Upvotes: 9