简体   繁体   English

如何在我启动一个程序的地方编写批处理文件,当该程序完成或关闭时,启动另一个程序

[英]How Can I Write a Batch File Where I Start one Program and When that Program Finishes or Closes, Start Another

For example: 例如:

@echo off
start C:\Windows\system32\dfrgui.exe /C

Wait for defragmentation to finish. 等待碎片整理完成。

start C:\"Program Files (x86)"\CCleaner\CCleaner.exe /AUTO

Wait for CCleaner to finish. 等待CCleaner完成。

start C:\Windows\system32\cleanmgr.exe /sagerun:1

and so on.. You get the point. 依此类推..您明白了。 How I can do this? 我该怎么做? Thanks. 谢谢。

Start can take a command line argument /WAIT eg 开始可以使用命令行参数/ WAIT,例如

@echo off
title Test cmd start

start /WAIT wait.cmd 5
start /WAIT cmd /k echo launched second command

pause

This simple example uses another script I have written (wait.cmd shown below) as the first command executed, as you will see if you test this with the /WAIT option specified the script allows the first command to finish before continuing: 这个简单的示例使用了我编写的另一个脚本(如下所示的wait.cmd)作为执行的第一个命令,因为您将看到是否使用指定的/ WAIT选项对其进行测试,该脚本允许第一个命令在继续之前完成:

@echo off
rem call with # of seconds to wait

set /a secs=%1
set /a ms=%secs%*1000
echo Process will wait for %secs% seconds and then continue...
ping 1.1.1.1 -n 1 -w %ms% > nul
echo.
exit

As a side note if you open a cmd session you can find out about the arguments that a command such as start accepts eg 作为附带说明,如果您打开cmd会话,则可以找到有关命令(例如start)接受的参数的信息,例如

在此处输入图片说明


Update following comment 更新以下评论

So to adapt the commands you listed in your question to finish before starting the next command in the script you could use: 因此,为了在脚本中开始下一个命令之前使问题中列出的命令适应完成,可以使用:

@echo off
start /WAIT C:\Windows\system32\dfrgui.exe /C
start /WAIT C:\"Program Files (x86)"\CCleaner\CCleaner.exe /AUTO
start /WAIT C:\Windows\system32\cleanmgr.exe /sagerun:1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何使该批处理文件启动,并且在2小时后它将关闭并启动同一程序? - How do i make this batch file start and after 2 hours it will shutdown and start the same program? 如何启动另一个程序并在 Python 脚本完成后保持运行? - How to start another program and keep it running after Python script finishes? 如何制作一个批处理文件来检测程序何时关闭然后重新启动应用程序? - How to make a batch file that detects when a program closes and then restarts the application? 我可以在Windows XP中将程序作为服务启动吗? - Can I start a program as a service in Windows XP? 如何使用 Windbg 从程序开始进行调试? - How can I debug from the start of a program with Windbg? 使用Windows批处理文件启动Java程序 - Use Windows Batch File to start a Java program 当 Windows 服务无法启动时,如何运行警报程序? - How can I run an alert program when a Windows Service fails to start? 如果要编程一些可以更改Windows中键盘/鼠标配置的东西,该从哪里开始? - Where do I start if I want to program something that can change the configuration of Keyboard/Mouse in Windows? 如何在其默认程序中启动文件,然后在脚本完成时关闭它? - How do I launch a file in its default program, and then close it when the script finishes? 在程序启动之前如何执行批处理文件? - How can I execute a batch file before a program starts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM