Inspired by MrBcx's Hide Console Window thread and Kliu's hideexec , here is an application to run hidden console applications. C code is the output of BCX Basic :
#include <windows.h>
int __cdecl __getmainargs(int*, char***, char***, int, int*);
int WINAPI WinMain (HINSTANCE hInst,HINSTANCE hPrev,LPSTR CmdLine,int CmdShow)
{
PROCESS_INFORMATION procinfo={0};
STARTUPINFO startinfo={0};
BOOL ProcResult= {0};
DWORD ExitCode= {0};
int argc,i;
char** argv;
char** env;
int doWildCard = 0;
__getmainargs(&argc,&argv,&env,0,&doWildCard);
ZeroMemory(&startinfo,sizeof(startinfo));
startinfo.cb=sizeof(startinfo);;
startinfo.dwFlags=STARTF_USESHOWWINDOW;
startinfo.wShowWindow=SW_HIDE;
ProcResult=CreateProcess(NULL,argv[1],NULL,NULL,FALSE,CREATE_NO_WINDOW|NORMAL_PRIORITY_CLASS,NULL,NULL, &startinfo, &procinfo);
ExitCode=0x10000;
ProcResult=(ProcResult!=0);
for(i=0; i<ProcResult; i++){
WaitForSingleObject(procinfo.hProcess,INFINITE);
GetExitCodeProcess(procinfo.hProcess, &ExitCode);;
CloseHandle(procinfo.hProcess);
CloseHandle(procinfo.hThread);
}
return ExitCode;
}
Very cool 8)
Thanks!
John Z
I do this for a upnp cli binary, but I use ShellExecute with flags that completely hide it. Is ShellExecute not sufficient for this?
Hi WiiLF23,
ShellExecute is practical and easier to use. The CreateProcess API has more control on the process creation stage.