WPF set default printer

How can I set a specific printer to default printer in WPF?
VBdotnet2005Asked:
Who is Participating?
 
anjosConnect With a Mentor Commented:
see here:
http://stackoverflow.com/questions/6388503/change-default-printer-within-wpf-application

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 }); 
   } 
}

Open in new window

0
 
VBdotnet2005Author Commented:
I don't see ManagementObjectSearcher after importing
Imports System.Management.Instrumentation
Imports System.Management
0
 
anjosCommented:
and if you try this:
http://stackoverflow.com/questions/3692384/missing-directive-or-assembly-reference-using-wmi-managementobjectsearcher

"You will have to rightclick the project -> add reference and add the System.Management assembly"
0
 
VBdotnet2005Author Commented:
I got it to work now.  Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.