Hey all,

I'm currently having a file I want to open using a program. The system does NOT have the file-extension associated with said program. However using the standard "let me choose what program to use" box when trying to open the file and selecting the program it runs just fine. (keep in mind I never enable "always open file with this program".. as I can't be sure my target clients have the file asosciation on their system...

Sooo I was trying this:
ShellExecute(Handle, nil, PChar(dir\myprogram.exe'), PChar(dir\dir\myfile.upx'), nil, SW_SHOWNORMAL);

This does not work however :( It seems to be just opening "myprogram.exe" without loading "myfile.upx"...

Again, manually double clicking myfile.upx and choosing myprogram.exe to open it it works 100% perfect... but I need delphi to do whatever windows is doing there itself on runtime... and again, I can't just make a file associassion and then use shellexecute as it has to work even if .upx isn't a registered extension to anything in Windows..

Thanks !

Sooo I was trying this:
ShellExecute(Handle, nil, PChar(dir\myprogram.exe'), PChar(dir\dir\myfile.upx'), nil, SW_SHOWNORMAL);

This does not work however :( It seems to be just opening "myprogram.exe" without loading "myfile.upx"...

If this does not work, that means that myprogram.exe is not equipped to open files specified on the command line.

Maybe you can try:

ShellExecute(Handle, nil, PChar('dir\dir\myfile.upx'), nil, nil, SW_SHOWNORMAL);

Edited 5 Years Ago by pritaeas: n/a

While I think this was the first thing I tried when trying to find the solution, looking at it again, it doesn't seem possible that this works ? I mean nowhere is the myprogram.exe specified so how would he know to use that program ?

Again if I double click the .upx file I get the windows "I have no clue what to do with this box, please tell me" if I then browse and pick myprogram.exe it works..

Correct, it wouldn't, but I thought it would open the "open with" screen.

You can try the following, perhaps that will work:

ShellExecute(Handle, nil, PChar('dir\myprogram.exe "c:\dir\dir\myfile.upx"'), nil, nil, SW_SHOWNORMAL);

Edited 5 Years Ago by pritaeas: n/a

Nope :( when running the code I get absolutely no response at all... (its not giving any error or trying to open anything visually at least)

This is proving harder then expected :( I thought because its so easily to do it manually that well code for that action would be straight forward :(

Have you tried setting the directory ...

ShellExecute(Handle, 'run', PChar(dir\myprogram.exe'), PChar(dir\dir\myfile.upx'), PChar(dir\dir\'), SW_SHOWNORMAL);

This article has been dead for over six months. Start a new discussion instead.