一聚教程网:一个值得你收藏的教程网站

热门教程

设置默认打印机

时间:2022-07-02 11:44:04 编辑:袖梨 来源:一聚教程网

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

热门栏目