Hello everybody and thanks for your time.
I'm developing some kind of monitoring application in C and I fell in need of getting the current tasks list. So I'm using tasklist and getting the output thanks to popen();
ptr = popen("tasklist /V", "r");
while(1)
{
if(fgets(temp, 255, ptr) == NULL) break;
fputs(temp, log);
}
The problem is that for some fractions of a second a cmd.exe window pops up and that's really disturbing, because it switches focus on that new window and it makes my application go to windowed-mode instead of fullscreen.
So, I've spent days looking on either popen ways or Windows itself ones to start that process in an 'hidden' mode/window but got no result. Things I already tried include:
cmd.exe /c tasklist /V
start /b cmd.exe /c tasklist /V
start /min /b cmd.exe /c tasklist /V
start /min cmd.exe /c tasklist /V
tasklist > somefile
I tried last one too so I would read the output from that somefile but seems like tasklist forces output to stdout since no data is written though file is created.
Hope in your answer and thank you anyway.
You can achieve this by calling CreateProcess
passing SW_HIDE
as the wShowWindow
field of the STARTUPINFO
struct and including CREATE_NO_WINDOW
in dwCreationFlags
.
This method is a little brittle because you may find your app running on a machine with a version of tasklist
that has a different output format.
If you want a list of all processes that are running you can call EnumProcesses
.