I have a batch file that will detect if the user has the .Net framework installed by going to the directory and checking if the CONFIG directory exists.
If the directory doesn't exist then the user doesn't have the .Net framework installed. The batch file will then continue on to install the .Net framework. However, there is a problem as the .Net frameworks need to be installed before running the setup to install my dialer. So I have put a PAUSE statement so the user will press any button to continue after the framework has been installed.
However, our client doesn't like this as some of their customers don't understand and they press a key before the framework has finished installing. This then causes the setup to fail as the framework haven't been installed first.
I am using the PAUSE that will wait for the user input. However, is there a way that the batch will wait until the framework is finished automatically instead of using the PAUSE command?
Many thanks for any suggestions,
@ECHO OFF
REM Copy the configuration file
copy config.xml "%AppData%\DataLinks.xml"
REM Search for the CONFIG file, if this doesn't exit then the user doesn't have the .Net framework 2.0
SET FileName=%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG
IF EXIST %FileName% GOTO INSTALL_DIALER
ECHO.You currently do not have the Microsoft(c) .NET Framework 2.0 installed.
ECHO.This is required by the setup program for MyApplication.
ECHO.
ECHO.The Microsoft(c) .NET Framework 2.0 will now be installed on you system.
ECHO.After completion setup will continue to install MyApplication on your system.
ECHO.
REM Install the .Net framework and wait for the user to input before install the dialer
PAUSE
ECHO Installing... Please wait...
SET FileName =
Start .\NetFx20SP2_x86.exe
ECHO Once the .Net Framework has completed. Press any key to continue to install the dialer.
PAUSE
Start .\setup.exe
ECHO ON
EXIT
REM .Net framework has been skipped contine to install the dialer.
:INSTALL_DIALER
ECHO *** Skiped Dotnet Framework 2.0.50727 ***
ECHO Installing... Please wait...
SET FileName=
Start .\setup.exe
ECHO ON
EXIT
you can use
START /WAIT NetFx20SP2_x86
too. remember that
REM comment
is equal to
::comment
and that using .\ is unnecessary, and file extensions are too, unless there are dirs/files with conflicting names. You also do not need cleaning the "filename" variable twice (the "=" pointing nothing twice) and
ECHO.something
is equal
ECHO something
only except for blank lines
you could also use
START /WAIT NetFx20SP2_x86.exe
the slash is to indicate that it is an option to the start command, not the target file. to see more of these options, look here (i would refer to it as a 'forward slash')
Just remove the START line from the call, like so:
.\NetFx20SP2_x86.exe
Start .\setup.exe
This will make the installation blocking, as in the batch file will stop processing until the NetFx20SP2_x86.exe
program terminates.
Ok I optimized your script, sort of:
@echo off
rem Copy the configuration file
copy config.xml "%AppData%\DataLinks.xml"
rem Search for the CONFIG file, if this doesn't exist then the user doesn't have the .Net framework 2.0
if not exist "%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG" (
echo You currently do not have the Microsoft(c) .NET Framework 2.0 installed.
echo This is required by the setup program for MyApplication.
echo.
echo The Microsoft(c) .NET Framework 2.0 will now be installed on you system.
echo After completion setup will continue to install MyApplication on your system.
echo.
Start /w .\NetFx20SP2_x86.exe
)
Start /w .\setup.exe
1: As you only use the CONFIG file for test purpose once, using a variable for it is useless. moreover, the "=" sign must be stuck to the variablename, otherwise you will create a variable with a space in it. "set filename =" and "set filename=" are two different things. Yes, a variable name can contaion multiple words and spaces, but one need to be extremely cautious about it, it can be hard to handle.
2: I would not recomment using '::' as a comment, sorry Camilo, because it does not work well within parenthesis. It would here, but if you take this track for all your batches, you might get into a problem later and you will wonder why your code is broken if you don't know this.
3: You don't need to end a script with exit, nor resetting to echo on, when a script reaches the end, it does reset the echo state and exit by itself.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With