【发布时间】:2011-04-27 07:09:03
【问题描述】:
我在尝试添加打印机驱动程序时收到此错误。
操作已被用户取消。 (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;
}
}
更新:
-
应用程序在 app.manifest 中请求管理权限 (requestedExecutionLevel level="requireAdministrator")
我在 UAC 开启甚至关闭时遇到同样的错误。
驱动程序未进行数字签名
如果我手动安装驱动程序,我会收到 Windows 安全警告,默认选项为“不要安装此驱动程序软件”(不幸的是,在运行上述代码时不会收到该消息)。
【问题讨论】:
-
似乎问题在于安装驱动程序或驱动程序本身的安全性/权利。假设这是一个普通的打印机驱动程序,你能通过控制面板安装驱动程序吗?