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

时间:2009-06-25 03:58:46

标签: batch-file

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

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

但是,我们的客户不喜欢这样,因为他们的一些客户不理解,他们在框架完成安装之前按下了一个键。这会导致设置失败,因为框架尚未首先安装。

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

非常感谢任何建议,

@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 个答案:

答案 0 :(得分:12)

你可以使用

START /WAIT NetFx20SP2_x86

太。 记住那个

REM comment

等于

::comment

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

ECHO.something

相等

ECHO something

除了空行

答案 1 :(得分:3)

您也可以使用

 START /WAIT NetFx20SP2_x86.exe

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

答案 2 :(得分:2)

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

.\NetFx20SP2_x86.exe
Start .\setup.exe

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

答案 3 :(得分:2)

好的,我优化了你的脚本,排序:

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

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

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

希望这有帮助。

相关问题