Click to See Complete Forum and Search --> : running exe


Tom Allitt
September 6th, 2001, 04:01 AM
I am wanting to run various different executable files when items are clicked in a list box control. How do I run an external exe file from within an application?

Regards

Tom

Cakkie
September 6th, 2001, 04:43 AM
You can use the Shell command

' start notepad
Shell "c:\windows\notepad.exe"




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Paul Ch
September 6th, 2001, 04:57 AM
Shell is alright unless you want to know when the program has finished.

You could try the following which will wait for the process to finish before continuing. Apologies for the source being in C++ but it should be easy to convert to VB.


int CALLBACK ExecCmd(char cCmdLine[])
{// Execute a command and wait for it to finish (Create a modal thread)
//
// Local variables
//
// si : Startup information
// pi : Process information

STARTUPINFO si;
PROCESS_INFORMATION pi;

// Zero startupinfo structure
ZeroMemory(&si, sizeof(STARTUPINFO));

// Initialise startupinfo structure
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USEPOSITION | STARTF_USESIZE;

// Create process (i.e. run the required command)
CreateProcess(NULL, cCmdLine, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);

// Wait for process to end
WaitForSingleObject(pi.hProcess, INFINITE);

// Close process handle
CloseHandle(pi.hProcess);
return TRUE;
}