Caml Light Posted April 25, 2012 Share Posted April 25, 2012 Hi guys, with tasklist command i need to save as txt all running processes, so i've created a batch file with:TASKLIST > processes.txtAt this point i would need to save as txt only the image names, without PID, session name and so on... simply a txt file in this format:csrss.exesvchost.exetaskmgr.exewininit.exewinlogon.exe...Is it possible to do it for you? Thank you in advance.Cheers Link to comment Share on other sites More sharing options...
tomasz86 Posted April 25, 2012 Share Posted April 25, 2012 FOR /F "skip=3" %%I IN ('tasklist.exe') DO ECHO>>processes.txt %%I Link to comment Share on other sites More sharing options...
Caml Light Posted April 25, 2012 Author Share Posted April 25, 2012 thank you but the processes.txt file only contains this:ECHO active.ECHO active.ECHO active.ECHO active.ECHO active.... Link to comment Share on other sites More sharing options...
tomasz86 Posted April 25, 2012 Share Posted April 25, 2012 (edited) It works fine here so it must be a different version of tasklist.exe to have different output than mine. You didn't mention your OS though Could you show an example how your tasklist.exe output looks like?Here it's sth like this:Image Name PID Session Name Session# Mem Usage========================= ====== ================ ======== ============System Idle Process 0 0 36 KSystem 8 0 28 Ksmss.exe 240 0 36 K Edited April 25, 2012 by tomasz86 Link to comment Share on other sites More sharing options...
Yzöwl Posted April 25, 2012 Share Posted April 25, 2012 How would this do for your needs:@ECHO OFF>PROCESSES.TXT TYPE NULFOR /F "DELIMS=," %%# IN ('TASKLIST /FI "STATUS eq RUNNING" /FO "CSV" /NH') DO ( >>PROCESSES.TXT ECHO=%%~#) Link to comment Share on other sites More sharing options...
Caml Light Posted April 25, 2012 Author Share Posted April 25, 2012 I've Win7 SP1 x64 and tasklist looks like from you... Link to comment Share on other sites More sharing options...
Caml Light Posted April 25, 2012 Author Share Posted April 25, 2012 Yzöwl your batch works perfectly! This time i only need to modifying it to save as text all processes, so i've delete this: /FI "STATUS eq RUNNING"@ECHO OFF>processes.log TYPE NULFOR /F "DELIMS=," %%# IN ('TASKLIST /FO "CSV" /NH') DO ( >>processes.log ECHO=%%~#)The problem now is that there are many duplicates, for ex. svchost.exe or csrss.exe are reported many times in the text file. Should you have an idea to list all processes one time only? Link to comment Share on other sites More sharing options...
Yzöwl Posted April 26, 2012 Share Posted April 26, 2012 The following should be sufficient although it does seem a little pointless not knowing how many separate instances of a process are running.@ECHO OFF>processes.log TYPE NULFOR /F "DELIMS=," %%# IN ('TASKLIST /FO "CSV" /NH') DO ( >NUL FINDSTR/IBE "%%~#" processes.log||>>processes.log ECHO=%%~#)Please note that cmd.exe, conhost.exe and tasklist.exe may be included only as a result of your query, but since there is no way of knowing I'd be inclined not to remove them from the logged results. Link to comment Share on other sites More sharing options...
Caml Light Posted April 27, 2012 Author Share Posted April 27, 2012 what to say... it's perfect! Thank you!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now