0

I have developed a batch file that is designed to check a value in a given excel sheet. And decides what to do depending of the value in the Excel sheet (value either 0 or more than zero)

Code is as follows

@echo off
setlocal EnableDelayedExpansion
cd\
D:
cscript //nologo testexcel.vbs

IF !ERRORLEVEL! EQU 1 (
  taskkill /F /IM explorer.exe
  *****MORE ACTIONS HERE*****
  SET running=0
  FOR /f "tokens=*" %%A IN ('tasklist^ /v^| findstr /i /c:"iexplore.exe"') DO SET running=1

  IF %running% == 0 (
    explorer.exe
  )

) ELSE ( 
  ***OTHER ACTIONS HERE***
)
exit

The code will run a VBscript using the cscript command and will; return a ERROR LEVEL value, either ERROR LEVEL is 1 or otherwise. For some reason I keep getting the below error:

( was unexpected at this time.

I understand that this may be happening due to the due to all the commands and variables within those parentheses are expanded. But I am using setlocal EnableDelayedExpansion but still getting the same error.

Stephan
  • 53,940
  • 10
  • 58
  • 91
user1111726
  • 157
  • 2
  • 8
  • 18
  • The code you've shown has an extra closing parentheses before the opening parentheses of the else statement. – T3RR0R Nov 22 '20 at 04:39
  • As the issue, based on the code shown is a typo, please delete this question as it is of no benefit to other users. – T3RR0R Nov 22 '20 at 04:41
  • My Apologies, I edited the question and removed the extra parenthesis. The issue still persists. – user1111726 Nov 22 '20 at 04:55
  • 1
    No need for delay-expand `errorlevel` here, but `running` should be. – Stephan Nov 22 '20 at 09:33
  • [your original](https://stackoverflow.com/posts/64950709/edit/b618ba0d-890f-4d03-b738-9deb032afd40) Did not contain the additional lines of code that would have made the expansion issue regarding the `running` variable (an unneccesary variable that could be replaced with `||` or `&&` conditional commands). In future when posting questions, please ensure the code you provide is an accurate minimal reproduceable example of the script you are experiencing issues with. Failure to do so results in wasting the time of other users in assessing your script for errors – T3RR0R Nov 22 '20 at 09:44
  • as if there is additional errors in unposted elements of the script it means an incomplete solution may be offered and additional time is spent reviewing updated code when all aspects of an issue could be identified the first time around if you had put sufficient information in your question in the first place. – T3RR0R Nov 22 '20 at 09:46

0 Answers0