MSFN Forum: TASKLIST - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

TASKLIST Rate Topic: -----

#1 User is offline   Caml Light 

  • Junior
  • Pip
  • Group: Members
  • Posts: 85
  • Joined: 03-October 03

Posted 24 April 2012 - 11:59 PM

Hi guys, with tasklist command i need to save as txt all running processes, so i've created a batch file with:

TASKLIST > processes.txt


At 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.exe
svchost.exe
taskmgr.exe
wininit.exe
winlogon.exe
...


Is it possible to do it for you? Thank you in advance.

Cheers :)


#2 User is offline   tomasz86 

  • http://windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,252
  • Joined: 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag

Posted 25 April 2012 - 12:24 AM

FOR /F "skip=3" %%I IN ('tasklist.exe') DO ECHO>>processes.txt %%I


#3 User is offline   Caml Light 

  • Junior
  • Pip
  • Group: Members
  • Posts: 85
  • Joined: 03-October 03

Posted 25 April 2012 - 01:01 AM

thank you but the processes.txt file only contains this:

ECHO active.
ECHO active.
ECHO active.
ECHO active.
ECHO active.
...


#4 User is offline   tomasz86 

  • http://windows2000.tk
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,252
  • Joined: 27-November 10
  • OS:XP Pro x86
  • Country: Country Flag

Posted 25 April 2012 - 01:50 AM

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 :whistle:

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 K
System                         8                         0         28 K
smss.exe                     240                         0         36 K

This post has been edited by tomasz86: 25 April 2012 - 01:53 AM


#5 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,369
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 25 April 2012 - 11:53 AM

How would this do for your needs:
@ECHO OFF
>PROCESSES.TXT TYPE NUL
FOR /F "DELIMS=," %%# IN ('TASKLIST /FI "STATUS eq RUNNING" /FO "CSV" /NH') DO (
	>>PROCESSES.TXT ECHO=%%~#)


#6 User is offline   Caml Light 

  • Junior
  • Pip
  • Group: Members
  • Posts: 85
  • Joined: 03-October 03

Posted 25 April 2012 - 11:54 AM

I've Win7 SP1 x64 and tasklist looks like from you...

#7 User is offline   Caml Light 

  • Junior
  • Pip
  • Group: Members
  • Posts: 85
  • Joined: 03-October 03

Posted 25 April 2012 - 12:13 PM

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 NUL
FOR /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?

#8 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,369
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 26 April 2012 - 12:28 PM

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 NUL
FOR /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.

#9 User is offline   Caml Light 

  • Junior
  • Pip
  • Group: Members
  • Posts: 85
  • Joined: 03-October 03

Posted 26 April 2012 - 06:03 PM

what to say... it's perfect! :thumbup

Thank you!!

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy