Advertisement
npocmaka

discon

May 16th, 2013
106
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.  
  15.     if "%~1" EQU "-h" (
  16.             goto :help
  17.     )
  18.      
  19.     if "%~1" EQU "/h" (
  20.             goto :help
  21.     )
  22.      
  23.     if "%~1" EQU "?" (
  24.             goto :help
  25.     )
  26.      
  27.     if "%~1" EQU "/?" (
  28.             goto :help
  29.     )
  30.      
  31.     shift
  32.  
  33.     for %%V in (/V /v v V) do (
  34.             if "%~1" EQU "%%V" (
  35.                     set "verbose=/V"
  36.             )
  37.     )
  38.      
  39.  
  40.     rem =========================
  41.    
  42.     setlocal enabledelayedexpansion
  43.     for /f "skip=1 tokens=1,2,3" %%S in ('query user') do (
  44.         set "current_user=%%S"
  45.         if "!current_user:~0,1!" NEQ ">" (
  46.            tsdiscon %%U %verbose%  
  47.         )
  48.     )
  49.     endlocal
  50.     goto :eof
  51.     :help
  52.         echo.
  53.         echo  %~n0 - disconets all session except the current
  54.         echo.
  55.         echo  %~n0 [/V]
  56.         echo.
  57.         echo    /V                     verbose information
  58.         echo.
  59.         echo  by Vasil "npocmaka" Arnaudov
  60.      
  61.     goto :eof
  62.    
  63. endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement