日期:2009-06-24  浏览次数:20478 次

using System.Management;
string PrinterName = "HP LaserJet 6L";

ManagementObjectSearcher query;
ManagementObjectCollection queryCollection;
string _classname="SELECT * FROM Win32_Printer";

query=new ManagementObjectSearcher(_classname);
queryCollection = query.Get();

foreach (ManagementObject mo in queryCollection)
{
if (string.Compare(mo["Name"].ToString(),PrinterName,true)==0)
{
mo.InvokeMethod("SetDefaultPrinter",null);
break;
}
}