Hi, i was wondering if it is possible to launch a .exe file using c++?

say i want to write a simple program which will ask the user if the would like to install the following.:(i am just making it up)

Please pick the number beside the program to launch it.
1)word.exe
2)notepad.exe
etc....

so how can i make it so that if 1 is picked, it will launch that .exe? The exe will be in the same folder as the program its self.

Sorry if this sounds unprofessional, i am only a month and a half into my c++ course.So if anyone could point me in the right direction, i would appreciate it.

Ya i read that in another forum too.....but people tend to stay away from the whole system ting? If you have timecould you explain to me? thanks. Also i am guessing that i can change the path of work.exe to something liek this?

system("C:\\word.exe");

An example:

#include <windows.h>

int main() {
  ShellExecute( NULL, NULL, "calc.exe", NULL, NULL, SW_SHOW );
}

Hi i get the following error when trying to use this

Error 1 error C2664: 'ShellExecuteW' : cannot convert parameter 3 from 'const char [9]' to 'LPCWSTR' c:\users\chaudhrys\desktop\n95 games for n-gage\testingexe\testingexe\testingexe.cpp 13


sorry not to experienced with all the system stuff yet.

You are probably using VC++ 2008 Express, which by default compiles everything for UNICODE. You have two choices:
(1) Turn UNICODE off. Projecct --> Properties --> Configuration Properties --> General. In the controls shown in the right-hand side of the screen look for "Character Set" (3d from the bottom) and change it to "Not set".

(2) Make the string UNICODE _TEXT("calc.exe")

No i am using VC pro but i will do what you said =) thanks. Its looking good.

To be complete, there is one other possibility. You can specifically call the non-unicode function by appending A to the function name. The other methods are probably better, though. ShellExecuteA(...);

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