How can I execute an external exe from Visual C++?

Status
Not open for further replies.

Moof

Full Member level 2
Joined
Nov 21, 2003
Messages
149
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Location
Argentina
Activity points
1,230
Visual C++ problem

How can i execute an external exe from visual c++, for example notepad.exe??
 

Re: Visual C++ problem

Moof said:
How can i execute an external exe from visual c++, for example notepad.exe??

Code:
#include <process.h>

char* argv[]={"param1","param2"};   // command-line parameters for notepad.exe

void main(void) {
	_execvp("notepad.exe",argv);    // will search for notepad.exe in current folder and in PATH
}
 

    Moof

    Points: 2
    Helpful Answer Positive Rating
Visual C++ problem

Hi,
Use the CreateProcess() windows API, its recommended by microsoft for launching any new applications.
Read more on CreateProcess on msdn.
 

Re: Visual C++ problem

simple way

SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "Notepad.exe"
ShExecInfo.lpParameters = "c:\\text.txt";
ShExecInfo.lpDirectory = NULL;

ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
 

Visual C++ problem

Simpler Way

CreateProcess("Notepad.exe",NULL,NULL,NULL,FALSE,0,NULL,NULL,NULL,NULL);
 

    Moof

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…