尝试添加打印机驱动程序时出现此错误。该操作已被用户取消。 (来自HRESULT的例外:0x800704C7)
操作被用户取消。 (异常来自HRESULT:0x800704C7)
我在这里做错了什么?
Public Function AddDriver(ByVal DriverName As String, ByVal InfFile As String) As Boolean
Try
Dim PRNADMIN As New PRNADMINLib.PrintMaster
Dim Drv As New PRNADMINLib.Driver
Drv.ModelName = DriverName
Drv.InfFile = InfFile
PRNADMIN.DriverAdd(Drv)
Return True
Catch ex As Exception
MessageBox.Show(ex.Message, frmMain.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Return False
End Try
End Function
这里谈到的C#版本
public bool AddDriver(string DriverName, string InfFile)
{
try {
PRNADMINLib.PrintMaster PRNADMIN = new PRNADMINLib.PrintMaster();
PRNADMINLib.Driver Drv = new PRNADMINLib.Driver();
Drv.ModelName = DriverName;
Drv.InfFile = InfFile;
PRNADMIN.DriverAdd(Drv);
return true;
} catch (Exception ex) {
MessageBox.Show(ex.Message, frmMain.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
}
UPDATE:
在app.manifest的应用程序请求管理权限(requestedExecutionLevel水平= “requireAdministrator”)
我得到与UAC On或甚至OFF相同的错误。
的驱动程序没有数字签名
如果我手动安装驱动程序,我得到的Windows安全警告,与“不安装此驱动程序软件”作为默认选项(不幸的是,没有得到该消息,同时运行上面的代码)。
似乎问题在于安装驱动程序或驱动程序本身的安全/权限。假设这是一个普通的打印机驱动程序,您可以通过控制面板安装驱动程序。 – 2011-04-27 07:36:41