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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
Ok thanks, I will take another look..
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.