May 12, 201016 yr im trying to get this bach work, but i cant!it is very simple, but i have problems with the syntaxis:IF EXIST "C:\1.exe" RUN /wait "C:\1.exe"ELSEshutdown -rEXITthe shutdown -r is for reboot the pc if the file doesnt existanyone can help me?
May 12, 201016 yr Here goes nothing.if exist "C:\1.exe" (Start /wait "C:\1.exe")ELSE (shutdown -r)exit
May 12, 201016 yr Author thank you very mthis message appears:"Windows is going to be restart"is any way to hide this and restart?
May 12, 201016 yr Could change it to thisSHUTDOWN -r -f -t 01or thisWMIC OS Where Primary=TRUE Call RebootMore details
May 13, 201016 yr Author with this it should workSHUTDOWN -r -f -t 01thank you very much other question:if exist "%CDROM%\Autowpi.exe" (Start /wait "%CDROM%\Autowpi.exe")ELSE (SHUTDOWN -r -f -t 01)exitafter execute autowpi.exe i need to run other application, so how can specify that?this is what i have tried but it doesnt work:if exist "%CDROM%\Autowpi.exe" (Start /wait "%CDROM%\Autowpi.exe") run "C:\application.exe" ELSE (SHUTDOWN -r -f -t 01)exit
May 13, 201016 yr after execute autowpi.exe i need to run other application, so how can specify that?this is what i have tried but it doesnt work:if exist "%CDROM%\Autowpi.exe" (Start /wait "%CDROM%\Autowpi.exe" && start /wait "C:\application.exe") ELSE (SHUTDOWN -r -f -t 01)exitthe double ampersand && means run the second command if (and only if) the first command is successful.
May 13, 201016 yr after execute autowpi.exe i need to run other application, so how can specify that?this is what i have tried but it doesnt work:if exist "%CDROM%\Autowpi.exe" (Start /wait "%CDROM%\Autowpi.exe") run "C:\application.exe" ELSE (SHUTDOWN -r -t 0)exitI'd suggest you don't confuse your script with concatenation!I would also suppose that using an if else is not required, by rebooting on failure as your first command, the two other commands wouldn't run anyhowIF NOT EXIST %CDROM%\Autowpi.exe SHUTDOWN -r -d p:4:2 -t 0%CDROM%\Autowpi.exe%SYSTEMDRIVE%\application.exeIf for some reason the commands start running before the supposedly immediate reboot, you could add START /WAIT before SHUTDOWN!
May 24, 201016 yr Author sorry guys for a late reply...my pc was infected with virus i have tried to make this run on Windows7, but it doesnt worki still having problem with this:IF EXIST "%CDROM%\1.exe" RUN /wait "%CDROM%\1.exe"ELSERUN /wait "%CDROM%\2.exe"EXITso..following Yzöwl instructions, i have tried this:if exist "%CDROM%\1.exe" (Start /wait "%CDROM%\1.exe") run "C:\2.exe" ELSE (run "C:\2.exe")exiti have replaced shutdown command for 2.exe application...but there is no way to run this cmd ok on W7! dont know why! need help
May 24, 201016 yr exact fault code is:@echo offFOR %%i IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\autowpi.exe (SET CDROM=%%i: && start/b/Wait %CDROM%\autowpi.exe && "%~dp0Install.exe" /silent /restart /l=Default) ELSE ("%~dp0Install.exe" /silent /restart /l=Default)
May 24, 201016 yr You should have just tried my example, I have answered this question two posts back. 1) double check your parenthesis (), as they need to go around both commands before the "Else" statement. Follow the sample I posted. It is tested and working.2) include the double ampersand && between your first and second commands, just like in my example3) you do not "Run" anything, there is no such thing as the "run" command inside of batch environment. Instead you should "start /wait" both commands so that your script does not move on before you are done. C:\Users\MrJinje>run'run' is not recognized as an internal or external command,operable program or batch file.EDIT: Also %CDROM% is not defined in any examples here, except for Maestro's. You may be better off just editing his sample to suit your needs. Edited May 24, 201016 yr by MrJinje
May 24, 201016 yr so..following Yzöwl instructions, i have tried this:I would call that "completely ignoring Yzöwl suggestions" You need to get a basic understanding of IF ELSE:IF CONDITION==TRUE DO_SOMETHING ELSE DO_ANOTHER_THINGis equivalent to:IF CONDITION==TRUE (DO_SOMETHING) ELSE (DO_ANOTHER_THING)If you need more than one action performed, you need to use a single ampersand:IF CONDITION==TRUE (DO_SOMETHING&DO_THIS&DO_THAT) ELSE (DO_ANOTHER_THING&ALSO_DO_THIS)Or, more easily and readable, structure the code on multiple lines:IF CONDITION==TRUE (DO_SOMETHING) ELSE (DO_ANOTHER_THING)The above allows for mutiple commands WITHIN brackets:IF CONDITION==TRUE (DO_SOMETHINGDO_THISDO_THAT) ELSE (DO_ANOTHER_THINGALSO_DO_THIS)jaclaz
May 24, 201016 yr <snip />so..following Yzöwl instructions, i have tried this:if exist "%CDROM%\1.exe" (Start /wait "%CDROM%\1.exe") run "C:\2.exe" ELSE (run "C:\2.exe")exit<snip />Actually if you look they are not my instructions at all, it is the exact same structure you posted last time, (which I corrected), the only difference is that you've changed 'Autowpi.exe' for '1.exe', 'application.exe' for '2.exe' and 'SHUTDOWN -r -t 0' for '2.exe'.Looking at what you've posted I'm assuming that this will do the same thing:IF EXIST "%CDROM%\1.EXE" (START "" /WAIT "%CDROM%\1.EXE")"C:\2.EXE"In order for that and the other examples we've given you to work you need to ensure that you have defined the %CDROM% variable; (maestrodellaves has previously given you one way to do so).
May 26, 201016 yr Author well..i have tried on many ways but when %CDROM%\1.EXE doesnt exist, the cmd doesnt continue with the script execution (2.exe) and the cmd is closedif 1.exe exist, the cmd works excelent could be that "if" parameter is bad written?(i also have tried Yzöwl commands):IF EXIST "%CDROM%\1.EXE" (START "" /WAIT "%CDROM%\1.EXE")"C:\2.EXE"and thenif exist...else...if no exist...goto... &&...but no wayPD: if i have %cdrom% on a pendrive..or hard disk..all works fine, the problem is when %cdrom% is a cdrom or a dvd Edited May 26, 201016 yr by cloferba
Create an account or sign in to comment