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:
The application requests administration rights in app.manifest (requestedExecutionLevel level="requireAdministrator")
I get the same error with UAC On or even OFF.
The driver is not digitally signed
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).
If you want to force your application to demand elevated privileges, user App.manifest, as described in this question.
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.
User contributions licensed under CC BY-SA 3.0