China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 07:14
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Count the number of svchost.exe processes and display it View 823 Replies 4
Original Poster Posted 2010-05-17 14:22 ·  中国 湖北 武汉 电信
初级用户
★★
Credits 108
Posts 56
Joined 2007-05-07 16:00
19-year member
UID 87758
Gender Male
Status Offline
Floor 2 Posted 2010-05-17 15:06 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
@echo off
for /f "delims=" %%a in ('Tasklist /fi "Imagename eq svchost.exe"') do set/a a+=1&echo.%%a
set/a a-=2
echo.Total %a% svchost.exe&pause

Or:
@echo off
for /f %%a in ('Tasklist /nh /fi "Imagename eq svchost.exe"') do set/a a+=1
echo.Total %a% svchost.exe&pause
Or:
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in ('Tasklist /svc /fi "Imagename eq svchost.exe"') do echo.%%a&set a=%%a&if not "!a:~0,1!"==" " set/a n+=1
set/a n-=2
echo.Total %n% svchost.exe&pause
Or:
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in ('Tasklist /m /fi "Imagename eq svchost.exe"') do echo.%%a&set a=%%a&if not "!a:~0,1!"==" " set/a n+=1
set/a n-=2
echo.Total %n% svchost.exe&pause


[ Last edited by Hanyeguxing on 2010-5-17 at 15:18 ]
Floor 3 Posted 2010-05-17 15:11 ·  中国 湖北 武汉 电信
初级用户
★★
Credits 108
Posts 56
Joined 2007-05-07 16:00
19-year member
UID 87758
Gender Male
Status Offline
Thanks

Works well
Floor 4 Posted 2010-05-17 16:12 ·  中国 湖北 武汉 电信
初级用户
★★
Credits 108
Posts 56
Joined 2007-05-07 16:00
19-year member
UID 87758
Gender Male
Status Offline
set/a n-=2


Why add this???
Floor 5 Posted 2010-05-17 16:47 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Originally posted by xue0808 at 2010-5-17 16:12:
set/a n-=2


Why add this???

Because in these examples that use set/a n-=2, tasklist doesn't use the /nh parameter, so it also displays the 2 header lines, which is why they need to be subtracted.
Forum Jump: