设置默认打印机

类别:.NET开发 点击:0 评论:0 推荐:

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

本文地址:http://com.8s8s.com/it/it42973.htm