1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <algorithm>
#include <string>
#include <windows.h>
using namespace std;
int main( int argc, char **argv )
{
TCHAR* exepath;
TCHAR* cmdline;
STARTUPINFO startup_info;
PROCESS_INFORMATION process_info;
if (argc < 2) return 1;
cmdline = GetCommandLine();
#ifdef _UNICODE
TCHAR** wargv = CommandLineToArgW( cmdline, &argc );
exepath = wargv[ 1 ];
LocalFree( wargv );
#else
exepath = argv[ 1 ];
#endif
cmdline = search(
cmdline, cmdline +lstrlen( cmdline ),
exepath, exepath +lstrlen( exepath )
);
fill_n( (char*)&process_info, sizeof( PROCESS_INFORMATION ), 0 );
fill_n( (char*)&startup_info, sizeof( STARTUPINFO ), 0 );
startup_info.cb = sizeof( STARTUPINFO );
AllocConsole(); // make sure there is a console associated with this process
if (!CreateProcess(
exepath,
cmdline,
NULL,
NULL,
TRUE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&startup_info,
&process_info
))
return 2;
CloseHandle( process_info.hThread );
// wait for the child program to terminate
WaitForSingleObject( process_info.hProcess, INFINITE );
// Wait for the user
const TCHAR* prompt = TEXT( "Press any key to continue..." );
DWORD count;
WriteConsole(
GetStdHandle( STD_OUTPUT_HANDLE ),
prompt,
lstrlen( prompt ),
&count,
NULL
);
WaitForSingleObject(
GetStdHandle( STD_INPUT_HANDLE ),
INFINITE
);
return 0;
}
|