Solved

ShellExecute doesn't recognise a file association

Posted on 2003-10-23
9
1,178 Views
Last Modified: 2012-08-13
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?
0
Comment
Question by:Sassonian
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 5

Expert Comment

by:JMoon5FTM
ID: 9612137
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
 
LVL 1

Accepted Solution

by:
Gichamba earned 100 total points
ID: 9613403
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 9615541
Try FindExecutable API to locate associated program
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 27

Expert Comment

by:planocz
ID: 10183447
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
 
LVL 5

Assisted Solution

by:JMoon5FTM
JMoon5FTM earned 100 total points
ID: 10184193
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
 
LVL 27

Expert Comment

by:planocz
ID: 10185040
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 10185435
>>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
 
LVL 5

Expert Comment

by:JMoon5FTM
ID: 10194088
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now