Link to home
Start Free TrialLog in
Avatar of Answers2000
Answers2000

asked on

Hiding batch file's console

This is a follow up on https://www.experts-exchange.com/jsp/qShow.jsp?ta=winprog&qid=10224880 

I have a Win32 console program.  It is complicated but of old-design full of printf's etc.  I need the program to be invisible while running. I do this by calling FreeConsole.  This much works

The question is: the console program also kicks off batch files using system("file.bat");  Each type a batch file runs a console flashes up while it is running.  Is there anyway to hide these consoles.

Any quick fix simple solution gets an A
Avatar of jkr
jkr
Flag of Germany image

Switch from 'system()' to 'CreateProcess()' and use the 'SW_HIDE' flag in the 'STARTUPINFO' struct you're using, e.g.:

STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory ( &si, sizeof ( STARTUPINFO));

si.cb = sizeof ( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;

bRes = CreateProcess ( NULL,
pszCmd, // command line, sth. like 'cmd.exe /c file.bat'
NULL,
NULL,
TRUE,
NORMAL_PRIORITY_CLASS,
GetEnvironmentStrings (),
NULL,
&si,
&pi
);

CloseHandle( pi.hProcess);
CloseHandle( pi.hThread);
 
Avatar of Answers2000
Answers2000

ASKER

setting pszCmd is probably the trick I missed!

i can't test it till Friday, but I'll let you know then or soon after

What does /c option do ?
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial