批处理文件,等待安装完成,然后再转到下一行

时间:2021-08-22 02:07:38

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.

我有一个批处理文件,通过转到目录并检查CONFIG目录是否存在来检测用户是否安装了.Net框架。

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.

如果该目录不存在,则用户没有安装.Net框架。然后批处理文件将继续安装.Net框架。但是,存在一个问题,因为在运行安装程序以安装我的拨号程序之前需要安装.Net框架。所以我放了一个PAUSE语句,这样用户在安装框架后会按任意键继续。

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?

我正在使用等待用户输入的PAUSE。但是,有没有一种方法,批处理将等到框架自动完成而不是使用PAUSE命令?

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

4 个解决方案

#1


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

使用。\是不必要的,文件扩展名也是如此,除非有名称冲突的目录/文件。您也不需要两次清除“filename”变量(“=”指向两次)和

ECHO.something

is equal

ECHO something

only except for blank lines

只有空行除外

#2


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

斜杠表示它是start命令的选项,而不是目标文件。要查看更多这些选项,请查看此处(我将其称为“正斜杠”)

#3


Just remove the START line from the call, like so:

只需从通话中删除START行,如下所示:

.\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.

这将使安装阻塞,因为批处理文件将停止处理,直到NetFx20SP2_x86.exe程序终止。

#4


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.

1:由于您只使用CONFIG文件进行一次测试,因此使用变量是没用的。此外,“=”符号必须粘贴到变量名,否则您将创建一个带有空格的变量。 “set filename =”和“set filename =”是两回事。是的,变量名可以包含多个单词和空格,但是需要对它非常谨慎,它可能很难处理。

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.

2:我不建议使用'::'作为评论,对不起Camilo,因为它在括号内不能正常工作。它会在这里,但是如果你为所有批次都使用这个轨道,你可能会在以后遇到问题,如果你不知道这个,你会想知道为什么你的代码被破坏了。

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.

3:您不需要使用exit结束脚本,也不需要重置为echo on,当脚本到达结尾时,它会重置echo状态并自行退出。

Hope this helps.

希望这可以帮助。

#1


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

使用。\是不必要的,文件扩展名也是如此,除非有名称冲突的目录/文件。您也不需要两次清除“filename”变量(“=”指向两次)和

ECHO.something

is equal

ECHO something

only except for blank lines

只有空行除外

#2


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

斜杠表示它是start命令的选项,而不是目标文件。要查看更多这些选项,请查看此处(我将其称为“正斜杠”)

#3


Just remove the START line from the call, like so:

只需从通话中删除START行,如下所示:

.\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.

这将使安装阻塞,因为批处理文件将停止处理,直到NetFx20SP2_x86.exe程序终止。

#4


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.

1:由于您只使用CONFIG文件进行一次测试,因此使用变量是没用的。此外,“=”符号必须粘贴到变量名,否则您将创建一个带有空格的变量。 “set filename =”和“set filename =”是两回事。是的,变量名可以包含多个单词和空格,但是需要对它非常谨慎,它可能很难处理。

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.

2:我不建议使用'::'作为评论,对不起Camilo,因为它在括号内不能正常工作。它会在这里,但是如果你为所有批次都使用这个轨道,你可能会在以后遇到问题,如果你不知道这个,你会想知道为什么你的代码被破坏了。

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.

3:您不需要使用exit结束脚本,也不需要重置为echo on,当脚本到达结尾时,它会重置echo状态并自行退出。

Hope this helps.

希望这可以帮助。