Batch files of the third word "If not" is not reached

Hi community stackoverflow,

I am writing a batch file to perform some automatic computer maintenance and have included several anti-virus applications. For some reason, the third statement “if not” is never achieved.

:AV REM MSE if not '%MSE%'=='' ( Echo Scanning for viruses using Microsoft Security Essentials. Echo. %MSE% -Scan -ScanType 1 Echo. GOTO Defrag ) REM AVG if not '%AVG%'=='' ( Echo Scanning for viruses using AVG. Echo. %AVG% /COMP /QT /TRASH Echo. GOTO Defrag ) REM NOD32 if not '%NOD32%'==''( Echo Scanning for viruses using NOD32. Echo. if '%NOD32%'=='' GOTO NOD32NotFound %NOD32% /aind /auto /log-file="%userprofile%\Desktop\Scan_Results.txt" Echo. GOTO Defrag ) REM If all else fails... GOTO AVNotFound 

Currently, there are three blocks of codes, one for each antivirus program. Each block of code is executed only when the variable% AVG %% MSE% or% NOD32% is not empty, that is, it points to a valid file. I assign variables using code:

 if exist "%programfiles(x86)%\AVG\AVG2012\avgscana.exe" set AVG="%programfiles(x86)%\AVG\AVG2012\avgscana.exe" 

All three blocks of code work fine, nothing works with encoding. The problem is that regardless of the third block, it is never executed. So, in the current example, the code blocks are in the order of MSE, AVG, and NOD32. The NOD32 code block is not executed because it is the third block. Conversely, if I cut and paste the blocks in a different order with the AVG code block being the third block, it will not execute.

Any ideas?

Any suggestions?

Edited for clarification.

+4
source share
3 answers

There is no space in the line:

 if not '%NOD32%'==''( 

Try:

 if not '%NOD32%'=='' ( 

When I tried the script, this line caused a crash. After changing the line, it worked.

+2
source

Are the variables %MSE% , %AVG% or %NOD32% batch files? If so, you will need to call them using the "call" instead (for example, call %AVG% )

If you call the batch file from another, the first one will exit after the second is executed, unless it is called with a "call".

+2
source

Do any of your variables %AVG% , %NOD32% or %MSE% have parentheses? Could they be in the path of C:\Program Files (x86)\ ? The bracket closes the branch prematurely.

Put quotation marks around the executable part of the commands, for example:

 "%MSE%" -Scan -ScanType 1 
0
source

Source: https://habr.com/ru/post/1382981/


All Articles