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

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).

c#
.net
vb.net
uac
asked on Stack Overflow Apr 27, 2011 by OrElse • edited Apr 27, 2011 by OrElse

3 Answers

1

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).

answered on Stack Overflow Apr 27, 2011 by Marius Bancila
0

If you want to force your application to demand elevated privileges, user App.manifest, as described in this question.

answered on Stack Overflow Apr 27, 2011 by abatishchev • edited May 23, 2017 by Community
0

I'm sure 100% but it looks like when running silently from your script, the warning about your driver is not digitally signed can't be displayed and therefore defaults to Cancel the installation.

Have you tried to digitally sign your driver with a self-signed certificate? If it installs after signing, then the reason is with the warning.

answered on Stack Overflow Apr 28, 2011 by Alexey Ivanov

User contributions licensed under CC BY-SA 3.0