Solved

ShellExecute doesn't recognise a file association

Posted on 2003-10-23
9
1,173 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
Comment Utility
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
Comment Utility
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
Comment Utility
Try FindExecutable API to locate associated program
0
 
LVL 27

Expert Comment

by:planocz
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Assisted Solution

by:JMoon5FTM
JMoon5FTM earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 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

9 Experts available now in Live!

Get 1:1 Help Now