Advertisement
npocmaka

sesskill

May 16th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. :sesskill
  3. rem -- kills all processes by given name except for the current session
  4. rem -- by Vasil "npocmaka" Arnaudov
  5. setlocal
  6.     set exe_name=%~1
  7.    
  8.    
  9.     rem =========================
  10.     rem == parsing parameters ==
  11.      
  12.     set exe_name=%~1
  13.      
  14.     if "%~1" EQU "" (
  15.             goto :help
  16.     )
  17.      
  18.     if "%~1" EQU "-h" (
  19.             goto :help
  20.     )
  21.      
  22.     if "%~1" EQU "/h" (
  23.             goto :help
  24.     )
  25.      
  26.     if "%~1" EQU "?" (
  27.             goto :help
  28.     )
  29.      
  30.     if "%~1" EQU "/?" (
  31.             goto :help
  32.     )
  33.      
  34.     shift
  35.  
  36.     for %%V in (/V /v v V) do (
  37.             if "%~1" EQU "%%V" (
  38.                     set "verbose=/V"
  39.             )
  40.     )
  41.      
  42.  
  43.     rem =========================
  44.    
  45.     setlocal enabledelayedexpansion
  46.     for /f "skip=1 tokens=1,2,3" %%S in ('query user') do (
  47.         set "current_user=%%S"
  48.    
  49.         if "!current_user:~0,1!" NEQ ">" (
  50.             for /f "tokens=2 delims= " %%M  in ('tasklist ^| find ^"%exe_name%^"') do (
  51.                 tskill "%%M"  %verbose%  /ID:%%U
  52.             )
  53.            
  54.         )
  55.     )
  56.     endlocal
  57.     goto :eof
  58.     :help
  59.         echo.
  60.         echo  %~n0 - kills all processes by given name except for the current session
  61.         echo.
  62.         echo  %~n0 executable [/V]
  63.         echo.
  64.         echo    executable             executable to be terminated.
  65.         echo    /V                     verbose information
  66.         echo.
  67.         echo  by Vasil "npocmaka" Arnaudov
  68.      
  69.     goto :eof
  70.    
  71. endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement