Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理文件,以便在移动到下一行之前等待安装完成_Batch File - Fatal编程技术网

Batch file 批处理文件,以便在移动到下一行之前等待安装完成

Batch file 批处理文件,以便在移动到下一行之前等待安装完成,batch-file,Batch File,我有一个批处理文件,可以通过转到目录并检查配置目录是否存在来检测用户是否安装了.Net framework 如果目录不存在,则用户没有安装.Net framework。批处理文件将继续安装.Net framework。但是,存在一个问题,因为在运行安装程序安装拨号程序之前需要安装.Net Framework。因此,我放置了一个暂停语句,以便用户在安装框架后按任意按钮继续 然而,我们的客户不喜欢这样,因为他们的一些客户不理解,他们在框架安装完成之前按下了一个键。这会导致安装失败,因为尚未首先安装框

我有一个批处理文件,可以通过转到目录并检查配置目录是否存在来检测用户是否安装了.Net framework

如果目录不存在,则用户没有安装.Net framework。批处理文件将继续安装.Net framework。但是,存在一个问题,因为在运行安装程序安装拨号程序之前需要安装.Net Framework。因此,我放置了一个暂停语句,以便用户在安装框架后按任意按钮继续

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

我使用的暂停将等待用户输入。但是,是否有一种方法可以让批处理等待框架自动完成,而不是使用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

只需从呼叫中删除起始行,如下所示:

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

您也可以使用

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

您可以使用

START /WAIT NetFx20SP2_x86
也是。 记得吗

REM comment
等于

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

平等

ECHO something

只有空行除外

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

@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:由于您仅将配置文件用于测试目的一次,因此使用变量是没有用的。此外,“=”符号必须固定在variablename上,否则将创建一个带有空格的变量“set filename=“”set filename=“是两个不同的东西。是的,一个变量名可以包含多个单词和空格,但是需要非常小心,它可能很难处理

2:我不建议使用“::”作为注释,对不起,卡米洛,因为它在括号内不起作用。在这里可能是这样,但如果您对所有批处理都采用此跟踪,您可能会在以后遇到问题,并且您会想,如果您不知道这一点,为什么您的代码会被破坏

3:您不需要使用退出来结束脚本,也不需要在上重置为回显,当脚本到达结束时,它会重置回显状态并自行退出


希望这有帮助。

您好,这里的所有解决方案都有效。但是,我想知道WAIT命令前面的反斜杠是什么意思,即/WAIT我只是想知道。如果用户在安装过程中取消,安装框架大约需要5分钟。是否有退出批处理文件的方法。当我测试时,安装程序运行了,然后失败了,因为用户取消了框架的安装。谢谢,命令行上的“帮助启动”将告诉您/WAIT的作用:“启动应用程序并等待它终止。”。顺便说一句,它是正斜杠或实线,不是反斜杠。如果你幸运的话,安装程序有一个返回值。启动安装程序后,您可以输入“if errorlevel 1 goto:eof”。如果安装程序有退出代码以防被取消(或无法完成),则应立即退出批处理文件,而不执行更多批处理文件。您还可以检查是否安装了批处理文件,因为它将创建框架文件,如果取消安装,则这些文件将不存在。基本上,它将使用相同的IF EXIST%FileName%…来检查框架。IF-EXIST语句的速度非常快,因此它是检查框架的可靠方法,即使用户由于任何可能的windows崩溃而杀死了安装程序。在这种情况下,安装程序不会返回errorlevel。正斜杠和hiphen(-)通常用于启动参数,但它们没有任何意义,只是很常见。
@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