Solved

ShellExecute doesn't recognise a file association

Posted on 2003-10-23
9
1,185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

691 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