I get "taskkill was not expected" when I run the following code. The program closes before I can set the value of %stop%. How can i fix this error?
@echo off
set ucs=ucs.exe
cls
echo.
echo Check %ucs%...
tasklist /FI "IMAGENAME eq %ucs%" 2>NUL | find /I /N "%ucs%">NUL
if %errorlevel%==0 (
echo %ucs% is running!
echo You need to stop it before editing ucsdb
echo 1 - Stop
echo 0 - Menu
set /p "stop=Stop %ucs%?"
if %stop%==1 taskkill /im %ucs% /t && goto sqlitebrowser
if %stop%==0 goto sqlitemenu
if not %stop%==1 if not %stop%==2 echo Option "%stop%" not exist! && timeout /t 2 /nobreak >NUL && goto sqlitemenu
) ELSE (
echo %ucs% is not running
echo Loading SqliteBrowser...
timeout /t 2 /nobreak >nul
goto sqlitebrowser )
Code Edit:
setlocal EnableDelayedExpansion
cls
echo.
echo Check %ucs%...
pause
tasklist /FI "IMAGENAME eq %ucs%" 2>NUL | find /I /N "%ucs%">NUL
if %errorlevel%==0 (
echo %ucs% is running!
echo You need to stop it before editing ucsdb
echo 1 - Stop
echo 0 - Menu
set /p "stop=Stop %ucs%?"
if !stop!==1 taskkill /im %ucs% /t && goto sqlitebrowser
if !stop!==0 goto sqlitemenu
if not !stop!==1 if not !stop!==0 echo Options "!stop!" not exist! && timeout /t 2 /nobreak >nul && goto sqlitemenu
...
if not !stop!==1 if not !stop!==0 echo Options "!stop!" not exist! Not work properly