Skip to content

Instantly share code, notes, and snippets.

@deemru deemru/cmd_proxy.c
Created May 20, 2016

Embed
What would you like to do?
I use it to start UniFi Video with mongod without journaling
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <string.h>
#define POSTCUT ".exe"
#define POSTFIX ".original.exe"
HANDLE hProcess = INVALID_HANDLE_VALUE;
BOOL WINAPI HandlerRoutine( DWORD dwCtrlType )
{
if( hProcess != INVALID_HANDLE_VALUE )
{
TerminateProcess( hProcess, dwCtrlType );
WaitForSingleObject( hProcess, INFINITE );
CloseHandle( hProcess );
}
return 0;
}
int main( int argc, char * argv[] )
{
char cmd[MAX_PATH * 2] = { 0 };
int i;
SetConsoleCtrlHandler( HandlerRoutine, TRUE );
strcat( cmd, argv[0] );
if( strcmp( cmd + strlen( cmd ) - strlen( POSTCUT ), POSTCUT ) == 0 )
memcpy( cmd + strlen( cmd ) - strlen( POSTCUT ), POSTFIX, strlen( POSTFIX ) + 1 );
else
strcat( cmd, POSTFIX );
strcat( cmd, " " );
strcat( cmd, "--nojournal" );
strcat( cmd, " " );
for( i = 1; i < argc; i++ )
{
if( strcmp( argv[i], "--journal" ) == 0 )
continue;
strcat( cmd, argv[i] );
strcat( cmd, " " );
}
{
PROCESS_INFORMATION pi;
STARTUPINFOA si;
memset( &si, 0, sizeof( si ) );
si.cb = sizeof( STARTUPINFO );
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdOutput = GetStdHandle( STD_OUTPUT_HANDLE );
si.hStdError = GetStdHandle( STD_ERROR_HANDLE );
si.dwFlags = STARTF_USESTDHANDLES;
if( !CreateProcessA( NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi ) )
return 1;
CloseHandle( pi.hThread );
hProcess = pi.hProcess;
WaitForSingleObject( hProcess, INFINITE );
CloseHandle( hProcess );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.