Executing tasklist on Windows with popen in C without cmd.exe popup -


hello , thanks time.

i'm developing kind of monitoring application in c , fell in need of getting current tasks list. i'm using tasklist , getting output popen();

ptr = popen("tasklist /v", "r"); while(1) {     if(fgets(temp, 255, ptr) == null) break;     fputs(temp, log); } 

the problem fractions of second cmd.exe window pops , that's disturbing, because switches focus on new window , makes application go windowed-mode instead of fullscreen.

so, i've spent days looking on either popen ways or windows ones start process in 'hidden' mode/window got no result. things 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 1 read output somefile seems tasklist forces output stdout since no data written though file created.

hope in answer , thank anyway.

you can achieve calling createprocess passing sw_hide wshowwindow field of startupinfo struct , including create_no_window in dwcreationflags.

this method little brittle because may find app running on machine version of tasklist has different output format.

if want list of processes running can call enumprocesses.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -