Executable not opening using ShellExecute()
-
This is a continuation from my earlier thread so all could respond. When I try to open an executable from my program using the following line it opens the executable then immdiatley closes it.:
ShellExecute(NULL,_T("open"),_T("cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);
The executable is a GUI and it opens fine if I go to the directory and double click on it, but it wont open the window when I try to open it from my program. As I said earlier, I am using a relative path since my program will be at the root of a CD and the executable will be 1 to 2 layers down as it is here. Anyone know why? thanks -
This is a continuation from my earlier thread so all could respond. When I try to open an executable from my program using the following line it opens the executable then immdiatley closes it.:
ShellExecute(NULL,_T("open"),_T("cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);
The executable is a GUI and it opens fine if I go to the directory and double click on it, but it wont open the window when I try to open it from my program. As I said earlier, I am using a relative path since my program will be at the root of a CD and the executable will be 1 to 2 layers down as it is here. Anyone know why? thanksUsing relative paths is *always* asking for trouble. The fact that ShellExecute() doesn't appear to be working indicates that it's not finding the EXE :-) How do you know somebody won't copy your CD to a hard disk and run it from there? How do you know what the *current directory* will be when your main program is run. ShellExecute() starts from the current directory, not where the main program lives. I always figure out where my main program is using GetModuleFileName() and generate absolute paths relative to that.
The two most common elements in the universe are Hydrogen and stupidity. - Harlan Ellison Awasu 2.2 [^]: A free RSS/Atom feed reader with support for Code Project.
-
Using relative paths is *always* asking for trouble. The fact that ShellExecute() doesn't appear to be working indicates that it's not finding the EXE :-) How do you know somebody won't copy your CD to a hard disk and run it from there? How do you know what the *current directory* will be when your main program is run. ShellExecute() starts from the current directory, not where the main program lives. I always figure out where my main program is using GetModuleFileName() and generate absolute paths relative to that.
The two most common elements in the universe are Hydrogen and stupidity. - Harlan Ellison Awasu 2.2 [^]: A free RSS/Atom feed reader with support for Code Project.
Yes, I do understand that it starts from the current directory, that is why I start the relative path from the my program will be which is one directory up the tree which would be cd1/CBTNuggetsPlayer.exething I needed to know is the proper format for a relative path so i know I am doing it right.
-
This is a continuation from my earlier thread so all could respond. When I try to open an executable from my program using the following line it opens the executable then immdiatley closes it.:
ShellExecute(NULL,_T("open"),_T("cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);
The executable is a GUI and it opens fine if I go to the directory and double click on it, but it wont open the window when I try to open it from my program. As I said earlier, I am using a relative path since my program will be at the root of a CD and the executable will be 1 to 2 layers down as it is here. Anyone know why? thanksCNewbie wrote:
ShellExecute(NULL,_T("open"),_T("cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);
ShellExecute(NULL,_T("open"),_T("**.\\**cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);
Nibu thomas Software Developer
-
CNewbie wrote:
ShellExecute(NULL,_T("open"),_T("cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);
ShellExecute(NULL,_T("open"),_T("**.\\**cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);
Nibu thomas Software Developer
Just updating, I tried this and it still will not open the window, I just see the executable open in task manager then 1 second later it closes and I never see any window open:
ShellExecute(NULL,_T("open"),_T(".\\cd1\\CBTNuggetPlayer.exe"),NULL,NULL,SW_SHOW);
not sure what else to try. I've gone through the flags to no avail.