25
2022
10
15:25:27

Windows CMD Shell» TSKILL vs TASKKILL



推荐点击下面图片,通过本站淘宝优惠价购买:

image.png

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://hqyman.cn/post/2811.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:





休息一下,本站随机推荐观看栏目:


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: