Batch file that checks whether a certain process (ultrasurf) is running, then executes a shutdown if present -


i've obtained batch file internet:

@for /f "tokens=5 delims= " %%i in ('netstat -ano -p tcp ^| find "127.0.0.1"') taskkill /f /pid %%i 

this kills ultrasurf process, however, have check same process , shutdown if present.

i have tried following:

@for /f "tokens=5 delims= " %%i in ('netstat -ano -p tcp ^| find "127.0.0.1"') shutdown /s 

this issues shutdown command whether process running or not. need execute if present. appreciated.

your batch file not kill ultrasurf, kills processes on local host have open tcp ports.

if run resource monitor see lot of services have open tcp ports rpc servers. hence modified script executes immediate shutdown since command finds at-least 1 match.

modifying 1 of answers question

tasklist /fi "imagename eq ultrasurf.exe" 2>nul | find /i /n "ultrasurf.exe">nul if "%errorlevel%"=="0" shutdown /s /f 

warning: untested code


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -