0

Am trying to uninstall one application and after uninstallation I want to clean up some folders. This is the command I used to uninstall.

if %errorlevel% == 0 (
 start /wait /d "%folder%"\test setup.exe
 FOR /f "delims=" %%a IN (ftp.txt) DO (
  if %errorlevel% == 0 (call :skip)
 )

 :skip
 rd /s /q "%location%"
 rd /s /q "%folder%"\agent
)

Here my question is , even I cancel the uninstallation still its removing the folders.

Can anyone suggest me where am doing wrong.

Thanks In Advance.

3 Answers 3

1

First problem: a label within a block (a parenthesised series of statements) terminates the block (this may be version-dependent) Hence, the commands following the label will be executed regardless of what the result of the remainder of the block is.

Second problem: the routine :skip is terminated by an unbalanced ). This may be harmless in itself, but it does not terminate the routine. call :skip will continue to an exit or end-of-file before returning.

Third problem: Within a block statement (a parenthesised series of statements), the entire block is parsed and then executed. Any %var% within the block will be replaced by that variable's value at the time the block is parsed - before the block is executed - the same thing applies to a FOR ... DO (block).

Hence, IF (something) else (somethingelse) will be executed using the values of %variables% at the time the IF is encountered.

Two common ways to overcome this are 1) to use setlocal enabledelayedexpansion and use !var! in place of %var% to access the changed value of var or 2) to call a subroutine to perform further processing using the changed values.

So - in your case, the second if %errorlevel% == 0 will applt the value of errorlevel at the time the very first if in the snippet you show us was encountered, not the changed value depending on the processing.

Next problem is that you are excuting the for/f on ftp.txt and appear to do nothing with the data gathered from ftp.txt - %%a is not used at all in the routine, all it does is attempt to call :skip once for each line in ftp.txt.

So-

if %errorlevel% == 0 (
 start /wait /d "%folder%"\test setup.exe
 if not errorlevel 1 (call :skip)
)
goto :eof    


:skip
rd /s /q "%location%"
rd /s /q "%folder%"\agent
goto :eof

may do the job, assuming that errorlevel is set to non-zero if the uninstallation is cancelled. Note that the format if [not] errorlevel n applies to the run-time value of errorlevel whereas if %errorlevel% == 0 applies to the parse-time value.

Without knowledge of what ftp.txt and %%a are supposed to be used for, I've no idea what to do with them...

Sign up to request clarification or add additional context in comments.

Comments

0

try this edit:

if %errorlevel% == 0 (
start /wait /d "%folder%"\test setup.exe
FOR /f "delims=" %%a IN (ftp.txt) DO (
if %errorlevel% == 0 (call :skip) )
goto done
:skip
rd /s /q "%location%"
rd /s /q "%folder%"\agent ) 
:done

1 Comment

ok, so.... what exactly is the purpose of the for loop? you already know errorlevel is 0 if you are running the loop, and all it does is check that.... so what does it accomplish?
0

See if this works for you - If setup.exe returns a non-zero errorlevel then it will skip the folder removals.

  start "Title" /wait /d "%folder%\test" setup.exe
  if not errorlevel 1 (
    rd /s /q "%location%"
    rd /s /q "%folder%\agent"
  )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.