我正在尝试从我的应用程序打印时转移默认打印机。此代码正在开发但在IIS 7上托管应用程序时无法正常工作。
ManagementObjectCollection objManagementColl;
// class used to invoke the query for specified management collection
ManagementObjectSearcher objManagementSearch = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");
// invokes the specified query and returns the resulting collection
objManagementColl = objManagementSearch.Get();
foreach (ManagementObject objManage in objManagementColl)
{
if (objManage["Name"].ToString() == "EPSON Bill") // compares the name of printers
{
objManage.InvokeMethod("SetDefaultPrinter", null); // invoke [SetDefaultPrinter] method
break;
}
}