How to start an other program?!

Started by
3 comments, last by Impz0r 22 years, 5 months ago
hi, I''ve some problems with to start out of my program an other program. I''ve tried serveral WinApi functions out, but nothing will work for me..wtf?! Ok i will show you my code here : case 1: ShellExecute (m_hWnd, "open", "C:\myapp.exe", NULL, NULL, SW_SHOWNORMAL); case 2: WinExec ("C:\myapp.exe", SW_SHOW); case 3: STARTUPINFO si; PROCESS_INFORMATION pi; memset (&si, 0, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); CreateProcess ("C:\myapp.exe", NULL, NULL, NULL, 0, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, π); ok these are the solutions i tried out, but i lie on my first sentence :D, he started the program, but ever in the background, and i can''t bring him to show these app..wtf?! I use Win XP, mybee an rights problem?! Thanks alot for your help... Mfg Impz0r
Stay Evil & Ugly!
Advertisement
So you''re saying that the code compiles all right, and everything, only when you try to run it, the program opens but can''t be brought to the foreground? That''s really weird...
I use Case 1 to spawn notepad from one of my programs...pretty much exactly the same as you are except that I set the second parameter to NULL, like so:

const char *lpFile = "c:\\windows\\notepad.exe";
const char *lpParameters = "error.log";
const char *lpDirectory = ".\\";

ShellExecute(iParms->hwnd,NULL,lpFile,lpParameters,lpDirectory,SW_SHOWNORMAL);


which gets notepad to open the file error.log in the current directory just great. I don''t remember off-hand what the second paramater is supposed to do, (initial properties of the program?) but maybe that has something to do with it.
-david
int ExecuteCommand(char *cmd, int cmdShow)
{

STARTUPINFO startInfo;
int processStarted;
unsigned long result;
PROCESS_INFORMATION pi;

memset(&startInfo, 0, sizeof(STARTUPINFO));

startInfo.dwFlags = STARTF_USESHOWWINDOW;
startInfo.wShowWindow = cmdShow;

processStarted = CreateProcess(NULL, cmd, NULL, NULL, 0,
CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS,
NULL, NULL, &startInfo, π);

if ( processStarted == 0 ) {
return -1;
}

WaitForSingleObject(pi.hProcess, INFINITE);

result = 0;

if ( !GetExitCodeProcess(pi.hProcess, &result) ) {
// STILL_ACTIVE ??
// Impossible to get the exit code for command\n%s
return -1;
}

return result;

}
first, thanks for your replay,
i tryed the code from "Anonymous Poster" but he does the same, the app would execute but won''t show..wtf?!
What the hell is going on here?! Must be a bug of XP, or something, i thought maybee security problems?!

Thanks alot...

Impz0r
Stay Evil & Ugly!
yes, it usually is a bug in the operating system when a novice programmer tries something and it doesn''t work.. c''mon.

This topic is closed to new replies.

Advertisement