Our application, write in Delphi, generates a series of reports, most of then in PDF format, that opens automatically when it is generated. Adobe X introduced a feature that is enabled by default "Enable Protected Mode at Startup". The report pdf files are opened using "ShelExecute".
var
pdfFile: string;
begin
pdfFile := 'C:\Users\Ronaldo\Documents\appName\reports\file.pdf';
ShellExecute(0, 'open', PChar(pdfFile), '', '', SW_SHOW);
//
end;
Because of this new Adobe Reader new setting, under Win 7 or Vista, we are getting an error message when opening the document. Double clicking the document to open it does not give any problem. Is there a way to disable the protected method - or another way to open the document without getting the error (a workaround)?
*Some more information *
The PDF file is being generated on our server application, streamed to the client and the client generates the pdf (using Write) - First I though that could be the problem - but again, why the double click works fine.
I have create a dummy app that do nothing but use the same above code to open the pdf, and it works. I have checked the privileges of the application - all the same - the only difference is that the one that is not working is being installed on the OS using a proper installer - the other (the dummy one) I just created and dropped it there.
One of the comments ask about the file association - this should not be an issue since the application succeed in launching Adobe reader - Adobe reader then gives me the "access denied" error message. A double click on the same file works fine.
New info - 30/03/2011 - 2:50pm - New Zealand time
I have made a change to the code just to test the only one difference between the app itself and the dummy app. Instead of getting the file path and file name automatically, it now opens a OpenDialog - the Filename property of the opendialog is used as parameter to ShellExecute (as the comment after Ken answer states) - it works. Why is it that, when you get the file name from an open dialog, it works - note that I am not openning the file from the dialog - I'm getting the filename, and using it as a parameter to ShellExecute.
Updated code sample
When the user clicks the "generate report" button, the report is opened automatically after it is generated. Apart from that, there is a grid, showing all the generated reports so far, for that user - this is the code on the double click for that grid:
if GetSelectedReport <> nil then // this will check if the user selected an report
if TReportItemState(GetSelectedReport.State) in [risGenerated,risViewed] then // checks if the report selected is in the correct state to be displayed.
begin
fileName := TClientReportManager.Singleton.Directory+'\'+GetSelectedReport.Filename; // a string with the filePath + fileName
ShellExecute(0, 'open', pchar(fileName), '','', SW_MAXIMIZE); // command to open the file
end;
My first guess with the Opendialog working is that, the open dialog changes the CurrentDir - So I tried already the SetCurrentDir and ChDir to change the current directory to the one where the files are. No success.
Under Win 7, the file path is translated to C:\Users\Ronaldo\Documents\CompanyName\AppName
ShelExecute
sentence which your use to open the document? – MicelleA := 1;
On US keyboards the back quote is usually at the top left combined with the tilde ~ above the tab key. – Garrygarson