综合编程

The operation was canceled by the user. (Exception from HRESULT: 0x800704…

微信扫一扫,分享到朋友圈

The operation was canceled by the user. (Exception from HRESULT: 0x800704…
0

I get this error while trying to add a printer driver.

The operation was canceled by the user. (Exception from HRESULT: 0x800704C7)

Am i doing something wrong here?

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

Here comes the c# version

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:

  1. The application requests administration rights in app.manifest (requestedExecutionLevel level="requireAdministrator")

  2. I get the same error with UAC On or even OFF.

  3. The driver is not digitally signed

  4. If i install the driver manually i get the windows security warning, with "Don’t install this driver software" as the default option (And unfortunately, do not get that Message while running the code above).

There is not enough info to figure the exact reason, but I stumbled upon the same error when I was doing an operation that was requiring input from the user (accept or cancel the operation), but the application was not able to display that prompt (because it was a GUI-less app), so the default action was Cancel. However, most likely this has something to do with the UAC (you can test that by temporarily disabling the UAC).

展开阅读全文

微信扫一扫,分享到朋友圈

The operation was canceled by the user. (Exception from HRESULT: 0x800704…
0

华为让运维“拔掉烟囱”

上一篇

Gruntwork Newsletter, June 2019

下一篇

你也可能喜欢

评论已经被关闭。

插入图片
The operation was canceled by the user. (Exception from HRESULT: 0x800704…

长按储存图像,分享给朋友