| 1 |
/* |
| 2 |
|
| 3 |
Launcher stub for tlmgr gui (with hidden console window) |
| 4 |
|
| 5 |
////////////////////////////////////////////////// |
| 6 |
|
| 7 |
This version has been replaced with a version which triggers a UAC |
| 8 |
prompt when appropriate. See Master/source/tlmgr-gui_UAC.zip. |
| 9 |
|
| 10 |
////////////////////////////////////////////////// |
| 11 |
|
| 12 |
Originally written in 2011 by Tomasz M. Trzeciak, Public Domain |
| 13 |
|
| 14 |
compiling with gcc (size optimized): |
| 15 |
echo 1 ICON "tlmgr-gui.ico">tlmgr-gui.rc |
| 16 |
windres tlmgr-gui.rc tlmgr-gui-rc.o |
| 17 |
gcc -Os -s -mwindows -o tlmgr-gui.exe tlmgr-gui-rc.o tlmgr-gui.c |
| 18 |
|
| 19 |
compiling with tcc (ver. 0.9.25), extra small size |
| 20 |
windres tlmgr-gui.rc tlmgr-gui-rc.o |
| 21 |
tcc -o tlmgr-gui.exe tlmgr-gui-rc.o tlmgr-gui.c |
| 22 |
|
| 23 |
*/ |
| 24 |
|
| 25 |
#include <windows.h> |
| 26 |
|
| 27 |
static char msgbuf[4*MAX_PATH]; |
| 28 |
#define DIE(...) { \ |
| 29 |
_snprintf( msgbuf, 4*MAX_PATH, __VA_ARGS__ ); \ |
| 30 |
MessageBox( NULL, msgbuf, "ERROR!", MB_ICONERROR | MB_SETFOREGROUND );\ |
| 31 |
return 1; \ |
| 32 |
} |
| 33 |
|
| 34 |
static char cmdln[2*MAX_PATH]; |
| 35 |
|
| 36 |
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShowint ) { |
| 37 |
|
| 38 |
// get file name of this executable |
| 39 |
|
| 40 |
static char selfdir[MAX_PATH]; |
| 41 |
char *name, *ext, *s; |
| 42 |
DWORD nchars = GetModuleFileName(NULL, selfdir, MAX_PATH); |
| 43 |
if ( !nchars || (nchars == MAX_PATH) ) DIE( "cannot get own path" ); |
| 44 |
|
| 45 |
// make command to execute |
| 46 |
|
| 47 |
if ( s = strrchr(selfdir, '\\') ) *s = '\0'; // remove file name part |
| 48 |
strcat( cmdln, "\"" ); |
| 49 |
strcat( cmdln, selfdir ); |
| 50 |
strcat( cmdln, "\\tlmgr.bat\" -gui" ); |
| 51 |
|
| 52 |
// create child process |
| 53 |
|
| 54 |
STARTUPINFO si; |
| 55 |
PROCESS_INFORMATION pi; |
| 56 |
ZeroMemory( &si, sizeof(si) ); |
| 57 |
si.cb = sizeof(si); |
| 58 |
si.dwFlags = STARTF_USESHOWWINDOW; |
| 59 |
si.wShowWindow = SW_HIDE ; |
| 60 |
ZeroMemory( &pi, sizeof(pi) ); |
| 61 |
|
| 62 |
if( !CreateProcess( |
| 63 |
NULL, // module name (uses command line if NULL) |
| 64 |
cmdln, // command line |
| 65 |
NULL, // process security atrributes |
| 66 |
NULL, // thread security atrributes |
| 67 |
TRUE, // handle inheritance |
| 68 |
0, // creation flags, e.g. CREATE_NEW_CONSOLE, CREATE_NO_WINDOW, DETACHED_PROCESS |
| 69 |
NULL, // pointer to environment block (uses parent if NULL) |
| 70 |
NULL, // starting directory (uses parent if NULL) |
| 71 |
&si, // STARTUPINFO structure |
| 72 |
&pi ) // PROCESS_INFORMATION structure |
| 73 |
) DIE( "command execution failed: %s", cmdln ); |
| 74 |
|
| 75 |
return 0; |
| 76 |
|
| 77 |
} |