tags:

views:

2782

answers:

5

Hello,

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 contine to install the .Net framework. However, there is a problem as the .Net framwork 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
+1  A: 

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.

MiffTheFox
+1  A: 

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')

akf
+1  A: 

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

Camilo Martin
Hello, all solutions here worked. However, I am wondering what does the backslash mean in front of the WAIT command i.e. /WAIT
robUK
I am just wondering. It takes about 5 minutes to install the framework, if the user cancel during progress. Is there a way to exit the batch file. When I tested the setup ran and then failed because the user canceled the installation of the framework. Thanks
robUK
"help start" on the command line will tell you what /WAIT does: "Start application and wait for it to terminate.". It's a forward slash or solidus, by the way, not a backslash.
Joey
If you're lucky the installer has a return value. You can put "if errorlevel 1 goto :eof" after starting the installer. Iff the installer has an exit code in case it was cancelled (or otherwise couldn't complete) then this should exit your batch file right there without executing more of it.
Joey
You can also check if it was installed because it would create the framework files, and if the installation is canceled those files would not exist. basically it would use the same IF EXIST %FileName% ...to check for the framework. IF EXIST statements are really fast, so it's a reliable way of checking for the framework EVEN if the user killed the installer due to any possible windows-ish crash. in that scenario the setup wouldn't return an errorlevel. The forward slash and the hiphen (-) are commonly used to start parameters, but they don't mean anything, they are just commonplace.
Camilo Martin
+1  A: 

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.

Jay
A: 

I am looking for a script. I have installed NET framework (dotnetfx) I want that if this is exist do not install dotnetfx again.