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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: a very simple wrapper to spawn another process based upon the contents of runme.dat
//
//=============================================================================
#include <stdio.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
// runme.dat contains the command line to run (passed directly to createprocess() )
FILE *f = fopen( "runme.dat", "rb" );
if ( !f )
return -1;
char szCommand[MAX_PATH];
memset( szCommand, 0x0, sizeof(szCommand) );
fread( szCommand, sizeof(szCommand), 1, f );
fclose( f );
int iCh = 0;
while ( iCh < sizeof(szCommand) && szCommand[ iCh ] && szCommand[ iCh ] != '\r' && szCommand[ iCh ] != '\n' )
{
iCh++;
}
szCommand[ iCh ] = ' ';
szCommand[ iCh + 1 ] = 0;
strncpy( &szCommand[ iCh + 1 ], lpCmdLine, sizeof(szCommand) - iCh - 1 );
szCommand[ sizeof(szCommand) - 1 ] = 0;
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0x0, sizeof(si));
si.cb = sizeof(si);
memset(&pi, 0x0, sizeof(pi));
// run the command
if(!CreateProcess(NULL, szCommand, 0, 0, FALSE, NORMAL_PRIORITY_CLASS, 0, 0,&si, &pi))
{
return -1;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return 0;
}
|