更改默认打印机不能在IIS上工作

时间:2014-03-24 08:17:59

标签: asp.net-mvc-4 iis web-applications printing

我正在尝试从我的应用程序打印时转移默认打印机。此代码正在开发但在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;
            }
        }

0 个答案:

没有答案