Batch Script to wait for program to close by user before applying msi update

a 夏天 提交于 2020-01-03 02:52:13

问题


I'm using a network management tool to apply updates to software and I have an issue where if a users is already using the program you want to update the update will fail as you would expect. I have been trying to put together a batch script that will detect whether the the program is running and if it is the script will wait until the user closes down the program and the apply the msi update.

I've pretty much scoured google but can only really find previous scripts that kill the program first before proceeding and I don't want that to happen as the user may lose work.

Hope someone can help!


回答1:


@echo off

    start "" notepad.exe

:loop
    (tasklist | find /i "notepad.exe" && ( ping -n 2 localhost & goto loop)) >nul 

    echo Notepad closed

This just starts notepad.exe (the running program) and waits until it is closed. Adapt according to your needs




回答2:


`tasklist |find "programname"` 

will tell you if the programm is running:

if %errorlevel%==0 echo running

put just a little loop around it:

:loop
tasklist |find "programname" >nul
if %errorlevel%==0 (
  echo prgram running
  timeout 2>nul
  goto loop
)
echo program not running


来源:https://stackoverflow.com/questions/23008051/batch-script-to-wait-for-program-to-close-by-user-before-applying-msi-update

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!