Archived

This topic is now archived and is closed to further replies.

Impz0r

How to start an other program?!

Recommended Posts

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, &pi); 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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, &pi);

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;

}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
yes, it usually is a bug in the operating system when a novice programmer tries something and it doesn''t work.. c''mon.

Share this post


Link to post
Share on other sites