[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 816
  • Last Modified:

WPF set default printer

How can I set a specific printer to default printer in WPF?
0
VBdotnet2005
Asked:
VBdotnet2005
  • 2
  • 2
1 Solution
 
anjosCommented:
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now