• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1193
  • Last Modified:

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?
0
Sassonian
Asked:
Sassonian
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
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
 
AzraSoundCommented:
Try FindExecutable API to locate associated program
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now