Because I've found that TSKILL could be useful too.... :-)
Despite the TASKKILL is far more powerful ,TSKILL has also some advantages:
1. Home editions of Windows do not have TASKKILL
2. TSKILL can filter processes by session id ,while TASKKILL can do it only by user name. Which is useful when more than one person work on a remote machine with same credentials.
3. TSKILL can be used against remote machines if the current user has permissions to do it
One annoying thing about TSKILL is that it does not recognize process name if it has ".exe" suffix.
Here's a simple script that I'm using to kill all processes on a terminal by name except for the current user (could be easy remade to kill the processes only for current user)
@echo off
:sesskill
setlocal
rem =========================
rem == parsing parameters ==
set "exe_name=%~1"
echo %exe_name%| findstr /i /e ".exe" >nul 2>&1 && set "exe_name=%exe_name:~0,-4%"
for %%H in ( /h -h /help -help "" ) do (
if /I "%~1" equ "%%~H" goto :help
)
shift
for %%V in (/V /v v V) do (
if "%~1" EQU "%%V" (
set "verbose=/V"
)
)
rem =========================
setlocal enabledelayedexpansion
for /f "skip=1 tokens=1,2,3" %%S in ('query user') do (
set "current_user=%%S"
if "!current_user:~0,1!" NEQ ">" (
for /f "tokens=2 delims= " %%M in ('tasklist ^| find "%exe_name%"') do (
tskill "%%M" %verbose% /ID:%%U
)
)
)
endlocal
goto :eof
:help
echo.
echo %~n0 - kills all processes by given name except for the current session
echo.
echo %~n0 executable [/V]
echo.
echo executable executable to be terminated.
echo /V verbose information
echo.
goto :eof
endlocal
本文链接:https://www.kinber.cn/post/2811.html 转载需授权!
推荐本站淘宝优惠价购买喜欢的宝贝: