先添加对system.ManageMent的引用,然后查找出你要设置的打印机名称,
以下事例设置为file://nato/EPSON LQ-1600KIII共享打印机为默认
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Management;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private ManagementObjectSearcher query;
private ManagementObjectCollection queryCollection;
string _classname = "SELECT * FROM Win32_Printer";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
query=new ManagementObjectSearcher(_classname);
queryCollection=query.Get();
foreach (ManagementObject mo in queryCollection)
{
if (string.Compare(mo["Name"].ToString(), @"file://nato/EPSON LQ-1600KIII", true) == 0)
{ mo.InvokeMethod("SetDefaultPrinter",null);
break;
}
}
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yyldir/archive/2009/05/10/4164692.aspx