Created
May 20, 2016 21:32
-
-
Save deemru/a41883ff852ea34f547c78c567364206 to your computer and use it in GitHub Desktop.
I use it to start UniFi Video with mongod without journaling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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