Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DOS Script

Posted on 2013-01-09
5
Medium Priority
?
348 Views
Last Modified: 2013-01-09
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 ?

Thanks


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

       IF ERRCODE NEQ 0 start http://msdn.microsoft.com/en-us/library/ms%MSERROR%(v=vs.85).aspx
       IF ERRCODE NEQ 0 echo.This failed with ERROR: %ERRCODE%
Deploy.txt
0
Comment
Question by:AXISHK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:AXISHK
ID: 38761566
But the attached batch doesn't work unless I remove the statements that I mentioned above.

Any idea ?
0
 
LVL 58

Expert Comment

by:Bill Prew
ID: 38761571
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.

ECHO OFF
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

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

       IF !ERRCODE! NEQ 0 start http://msdn.microsoft.com/en-us/library/ms%MSERROR%(v=vs.85).aspx
       IF !ERRCODE! NEQ 0 echo.This failed with ERROR: %ERRCODE%
   )
   del \\%%A\c$\Temp\ChromeSetup.exe  	
)

Open in new window

~bp
0
 
LVL 58

Expert Comment

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

~bp
0
 

Author Comment

by:AXISHK
ID: 38761616
Return the error at this time ".aspx was unexpected at this time". Any idea ?

Tks
0
 
LVL 58

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 38761638
Try changing the START to this:

start "" "http://msdn.microsoft.com/en-us/library/ms%MSERROR%(v=vs.85).aspx"
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question