ShellExecute/File Association/Security under Windows Vista

We use ShellExecute to open PDF files after generation.  This works fine on 2000, XP and most Vista setups.

My problem is that one Vista machine opens the PDF in notepad.  File associations seem correct - the user has Acrobat reader installed and can manually open PDF files.  The user is not a local administrator.

Here is the code that opens the document:  ShellExecute(handle, 'open', Pchar(sPDFFileName) , nil, nil, SW_SHOWNORMAL);
GenasysTechnologiesIT ManagerAsked:
Who is Participating?
JohnjcesConnect With a Mentor Commented:
Sounds like Adobe may have been installed for administrator or "me only" when installed. As I recall, Acrobat reader has that option.

I would try to reinstall reader first. Somehow, during the install something went  wrong. It does seem weird that this user can double click a pdf document/file and have it open yet when ShellExecute-ing it will not... yet other similar Vista machines do. Is that a correct understanding? More than 1 Vista PCs mixed with some XP PCs.

Are you installing the latest reader version?

I believe I read about a similar problem here in the Delphi forum of EE. I do not believe he found a fix for his problem somewhat similar to this one on Vista.

Try using "runas" instead of open..
GenasysTechnologiesIT ManagerAuthor Commented:
Hi lyonst,

Thanks for your quick reply.  I tried the 'runas'-verb after initial Googling, but could not get it to open documents on XP nor Vista:

This works: ShellExecute(handle, 'runas', Pchar('c:\windows\notepad.exe') , nil, nil, SW_SHOWNORMAL);
This does not work: ShellExecute(handle, 'runas', Pchar('c:\testfile.pdf') , nil, nil, SW_SHOWNORMAL);

We do not want to hardcode 'runas' against 'C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Acrobat.exe filename' since some people may want to use Foxit Reader.  This would also mean that we need to detect the Adobe Acrobat installation directory.
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Ok thanks, I will take another look..
tobjectpascalConnect With a Mentor Commented:
You could always add an option for this.

procedure AFT(FileType, Association: AnsiString);
//   FileType = '.pas'
//   Association = 'C:\Program Files\Delphi4\Bin\Delphi32.exe'
 if length(FileType) = 0 then EXIT;
 if length(Association) = 0 then EXIT;
  with TRegistry.Create do
    if FileType[1] <> '.' then FileType := '.'+FileType;
    OpenKey('\'+FileType, True);
    System.Delete(FileType, 1, 1); // Remove the leading point from
    WriteString('', FileType+'File');
    OpenKey('\'+FileType+'File\Shell\Open\command', True);
    WriteString('', Association+' %1');

Re-Associate it from within the registry as an option / force depending.... using ShellExecute should give you the identical same result as double clicking on the file from explorer/my computer whatever, hold shift down on any PDF then right mouse click, select an app, tick the box to make it remember the application of choice or use the routine above, same thing.
GenasysTechnologiesIT ManagerAuthor Commented:
Hi Johnjces,

Your understanding is correct and your theory makes sense.  I will get the user to re-install and let you know if this works.
GenasysTechnologiesIT ManagerAuthor Commented:
The user re-installed Windows which resolved the issue...  I guess the exact cause remains an issue :(
The user reinstalled Windows! Ouch! Or did he reinstall Adobe Acrobat reader?


and thanks! Glad I could help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.