93Views1Replies

Author Options:

Please help a noob Answered

I have a script that kills processes listed in text file, i need it to also run listed processes if they are closed.
@echo off
echo Edvinas Petukas Mtnl_14
@echo off &setlocal enabledelayedexpansion
tasklist /fo list|find /i ".exe">%temp%\running.tmp
for /f "tokens=2*" %%a in (%temp%\running.tmp) do (
call :process %%b
)
pause

exit /b

:process
for /f "tokens=*" %%c in (sarasas.txt) do if "%*"=="%%c" (
set Answ=N
echo Isjungti procesa?
set /p Answ=Kill %*?
IF /I NOT "!Answ!"=="Y" GOTO :EOF
if errorlevel 1 goto :EOF
echo Killing %%c
taskkill /f /im "%%c"

)

Tags:DOS

Discussions

0
None
g-one

4 years ago

The following code will crate the file "veikiaproc.txt" with only the already running processes.

Your list in "sarasas.txt" shall contain the programs that you want to run. If the programs can be found in the %path% environment or they are registered in

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

it would be sufficient to have only the program name in the list, e.g.

cmd.exe

Otherwise you have to write the entire path, e.g.

C:\foo\bar.exe

:: ~~~~~~~ code ~~~~~~~~~

@echo off &setlocal DisableDelayedExpansion
>"veikiaproc.txt" (for /f delims^=^" %%i in ('tasklist /nh /fo csv') do echo %%i)

for /f "usebackq delims=" %%i in ("sarasas.txt") do (
>nul findstr /ixc:"%%~nxi" "veikiaproc.txt" && (
echo running %%i
) || (
echo NOT running %%i
start "" "%%i"
)
)

del "veikiaproc.txt"
pause

:: ~~~~~~~ code ~~~~~~~~~