Hiding batch file's console

This is a follow up on http://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
LVL 8
Answers2000Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
jkrConnect With a Mentor Commented:
<locking it knowing that it works> ;-)

The '/c' option makes cmd.exe execute the command and terminate when it's finished. As batch files are no executables but shell command files and a Win32 executable is needed for 'CreateProcess()', 'cmd.exe /c file.bat' creates a console that executes the batch file. '/k' would cause the console not to close after finishing the execution... This might also come in handy if you want to redirect the output of other apps, e.g. by using 'cmd.exe /c myapp.exe >> myapp.txt'
0
 
jkrCommented:
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);
 
0
 
Answers2000Author Commented:
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 ?
0
All Courses

From novice to tech pro — start learning today.