Kill process in batch file that matches certain name and user -
i have question ya'll...hopefully can help.
background: have, lets say, 6 .exe's launched 6 separate scheduled tasks (the .exe's named after client , - clientname_program.exe). 6 tasks run under 3 separate user accounts scheduling purposes. meaning, can have 2 processes running @ same time under different accounts (you can't run them simultaneously under 1 id). if utilize 1 id, have run one, wait end, wait next one.
issue: have code in batch file looks process , waits end...however, written when .exe name same processes (used program.exe before went clientname_program.exe). problem is, realized %tfproname% variable set name of client trying run...so it's not looking other tfproname's running under same computer business relationship stuck. create sense?
so, need to:
before starting client2_program under user account1, search other *_program process running under account1 , wait end. if runs long, run powershell script kill said process.
below code snippet:
:prvarchstart tasklist /fi "imagename eq %tfproname%" | find /i "%tfproname%" >nul if errorlevel 1 ( echo **** %time% - archive process not running...checking import/export process... **** >> "%logfilefolder%\%logfilename%" goto prvarchend ) else ( echo **** %time% - archive running...please wait...checking again... **** >> "%logfilefolder%\%logfilename%" ping 1.1.1.1 -n 1 -w 5000 >nul powershell "& '%scriptdirectory%\killtfproadmin.ps1'" goto prvarchstart ) :prvarchend
just test if line in tasklist
output passes 2 filters, business relationship , executable.
set "loop=0" set "looplimit=2" :prvarchstart set "process=" /f "tokens=2 delims=," %%a in (' tasklist /v /fo:csv /nh ^| findstr /l /c:"%username%" ^| findstr /l /c:"_program.exe" ') ( set /a "loop+=1" set "process=%%~a" ) if not defined process goto :prvarchend if %loop% geq %looplimit% ( taskkill /pid %process% /f goto :prvarchend ) ping -n 2 localhost >nul 2>nul goto :prvarchstart :prvarchend
if no process found, continue
if process found, anotate , increment loop counter
if limit reached, kill process else wait , repeat process
batch-file kill-process tasklist
No comments:
Post a Comment