如何创建一个批处理文件,经过一段时间后执行一个文件,但如果中断则执行另一个文件?

如何创建一个批处理文件,经过一段时间后执行一个文件,但如果中断则执行另一个文件?

我想自动运行批处理文件来安装 ms office 2007 或 2010。

我正在考虑有一个选项菜单 1.Office 2007 2.Office2010

我希望我的计时器在开始时启动..比如说 20 秒

如果我同时按下选项 2 开始安装 2010

如果剩余且超时 = 0,则开始安装 2007

@echo off
timeout /t 20
choice /n /c 2 /m "Press 2 for Office 2010 "
set /a m=2
set /a counter=0
if %counter% ==0 GOTO office2007
if %M%==2 GOTO office2010

:office2010
cd %windir%\system32\office2010.exe
start setup2010.exe

:office2007
cd %windir%\system32\office2007.exe
start setup007.exe

但我认为这是完全错误的方法

有什么帮助吗?

答案1

choice /?在 cmd 窗口中查看或阅读选择

:: Q:\Test\2017\08\31\SF_871434.cmd
@echo off
:loop
Cls
Echo Select office version to install
Echo(
Echo   [1]  Install Microsoft Office 2007
Echo   [2]  Install Microsoft Office 2010
Echo(
CHOICE.exe /N /C 12 /D 1 /T 20 /M "after 20 seconds delay defaults to [1] "
If ErrorLevel 2 Goto :office2010
If ErrorLevel 1 Goto :office2007
Goto :loop

:office2010
cd %windir%\system32\office2010.exe
start setup2010.exe
Goto :Eof

:office2007
cd %windir%\system32\office2007.exe
start setup007.exe
Goto :Eof

示例屏幕输出:

Select office version to install

  [1]  Install Microsoft Office 2007
  [2]  Install Microsoft Office 2010

after 20 secondss delay defaults to [1] 

答案2

除此之外,我建议您考虑使用 Office 自定义工具(使用“setup.exe /admin”开关运行它)来创建一个 msp 文件,以完全自动执行 setup.exe 过程。

Office 2007:

http://windowsitpro.com/windows/how-do-i-create-administrative-installation-microsoft-office-2007

Office 2010:

https://technet.microsoft.com/en-us/library/ff521767(v=office.14).aspx

相关内容