ShellExecute doesn't recognise a file association

I am using shellExecute to open various applications depending on their file association.  This generally works great.

However whenever I try to open a .ico file it doesn't find the file association and I get a no file association error.  Even though this file does have a file assocation and I can open .ico files from both explorer and start/run.

And part 2 of the problem...

I have trapped when there is no file association to shell out to OPEN WITH...  And this works fine.  However in the .ico case - if I check the ALWAYS USE THIS PROGRAM TO OPEN THESE FILES - it goes off and opens the file in the correct program - but it gets no file association again when I next run through the API.  

Where am I going wrong?
SassonianAsked:
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.

JMoon5FTMCommented:
I don't know what version of Windows you're using, but this might help.

Some versions of Windows have an API called RealShellExecute that takes the same parameters as ShellExecute.  Try calling RealShellExecute, but use error handling so you can fall back on ShellExecute on Windows versions that don't have RealShellExecute.
0
GichambaCommented:
Hello, I had a problem like( and it was just failing with .ico files). One way to go round it is use ShellExecute to launch the application you wish to use with the icon and then pass the icon as an argument like this:

ShellExecute Me.hWnd, "Open", "C:\Program Files\Microangelo 98\muedit.exe ", "C:\UserGuide.ico", "", SW_SHOWNORMAL

The argument "C:\UserGuide.ico", is the icon file i want to launch using application : "C:\Program Files\Microangelo 98\muedit.exe " 

You need to known in advance the application u wish to use to launch icons, if you dont,
i believe there is a way to get the app associated with a file extension, the following link to get the associated icon should give you a rough idea:
http://www.developerfusion.com/show/2982/3/
0

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
AzraSoundCommented:
Try FindExecutable API to locate associated program
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

planoczCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
No response from Sassonian from 10/24/2003 comment
Award points to Gichamba is recommend.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

planocz
EE Cleanup Volunteer
0
JMoon5FTMCommented:
I think RealShellExecute should work.  Since I don't have the same associations as Sassonian, I can't test this, and I can't point out any MS documentation because it doesn't exist.  However, this function has fixed all of the problems I've had with ShellExecute.  I believe ShellExecute continues to use old Win 9x UI for compatability, whereas RealShellExecute is what the shell actually calls under later versions of Windows.  There are similiar RealXXX functions for other Windows shell UI functions, too.

The proposed solution of FindExecutable wouldn't work if the association required the executable to be passed any parameters, and registry parsing all the options MS supports would be extremely difficult, since there's pretty much zip in the way of documentation of semi-random parameters like %L, %S, and such.  Since there doesn't seem to be any "legal" method defined for executing the file, I think what I've proposed is the easiest of the "illegal" methods to implement and most likely to work, now and in the future.
0
planoczCommented:
I will leave a recommendation in the Cleanup topic area that this question is:
No response from Sassonian from 10/24/2003 comment
Award points to Gichamba(50%) and JMoon5FTM(50%) is recommend.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

planocz
EE Cleanup Volunteer
0
AzraSoundCommented:
>>The proposed solution of FindExecutable wouldn't work if the association required the executable to be passed any parameters

What do you mean?  I thought you just passed the function a file name and it told you what program is used to open it.
0
JMoon5FTMCommented:
FindExecutable does return the program that opens the file...but Windows supports associating a filetype not just with a program, but with a particular commandline.  For example, instead of just "MyApp.Exe MyFile", the association could be for "MyApp.Exe /blah file=MyFile" or some other such thing.  The shell can deal with these things, but FindExecutable can't - it only returns the application path.

Because RealShellExecute isn't documented, the other method is good to fall back on, so the split seems reasonable to me.
0
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
Visual Basic Classic

From novice to tech pro — start learning today.

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.