DOS Script

Try to make the attached batch work.

If I only keep one statement in "else" clause and remove the following, it works fine. It seems that there can only be one statement in else statement. Any idea ?


       IF %ERRCODE% LEQ 499 set MSERROR=681382
       IF %ERRCODE% GTR 500 set MSERROR=681388

       IF ERRCODE NEQ 0 start
       IF ERRCODE NEQ 0 echo.This failed with ERROR: %ERRCODE%
Who is Participating?
Bill PrewCommented:
Try changing the START to this:

start "" ""
AXISHKAuthor Commented:
But the attached batch doesn't work unless I remove the statements that I mentioned above.

Any idea ?
Bill PrewCommented:
Your problem is likely the fact that you are assigning and checking environment variables inside a FOR loop. To do that you need to use delayed expansion. Try this instead, notice the new setlocal line, and the use of ! to reference variables inside the loop that are changed inside the loop.

setlocal EnableDelayedExpansion

SET PClist=pclist.txt

for /f "tokens=2-4 delims=/ " %%i in ('date/t') do set yyyymmdd=%%k%%i%%j
if not exist %yyyymmdd%\*.* md %yyyymmdd%

date /t > D:\Temp\%yyyymmdd%\Chrome.log
time /t >> D:\Temp\%yyyymmdd%\Chrome.log

FOR /F "usebackq delims=" %%A in ("%PClist%") DO (
   MD \\%%A\C$\Temp >NUL 2>&1
   ECHO INSTALLING CHROME IN [%%A] >> D:\Temp\%yyyymmdd%\Chrome.log
   COPY "\\HKFSVR01\share_drive\public\Google Chrome\ChromeSetup.exe" \\%%A\C$\Temp

   verify >null
   set ERRCODE=0
   REM REM PSEXEC \\%%A -accepteula C:\Temp\ChromeSetup.exe /install
   REM PSEXEC \\%%A -u hkm\admin -p xxxxx msiexec.exe /i  "\\HKFSVR01\share_drive\corporate\public\Google Chrome\GoogleChromeStandaloneEnterprise.msi" ALLUSERS=1 /q /norestart

   set ERRCODE=0
   IF '!ERRORLEVEL!'=='0' (
       echo Success! >> D:\Temp\%yyyymmdd%\Chrome.log
   ) else (
       echo Fail ! >> D:\Temp\%yyyymmdd%\Chrome.log

       IF !ERRCODE! LEQ 499 set MSERROR=681382
       IF !ERRCODE! GTR 500 set MSERROR=681388

       IF !ERRCODE! NEQ 0 start
       IF !ERRCODE! NEQ 0 echo.This failed with ERROR: %ERRCODE%
   del \\%%A\c$\Temp\ChromeSetup.exe  	

Open in new window

Bill PrewCommented:
Also, what ERRORLEVEL are you trying to check?  The result of the PSEXEC, or something else?

AXISHKAuthor Commented:
Return the error at this time ".aspx was unexpected at this time". Any idea ?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.