Run a windows command/script when a specific program opens/closes

对着背影说爱祢 提交于 2019-12-13 05:17:44

问题


Is there a simple way to run a small command or batch script when a specific program opens or closes? I thought there might be a way to make it create a Windows event that I could then use as a trigger in the Task Scheduler, but I couldn't find any events for it.

The program I'm trying to use as a trigger is VLC Media Player.


回答1:


you could wrap the call to vlc in a batch file:

call preexec.cmd
start /b /wait "" vlc.exe
call postexec.cmd

then just replace the shortcut to start vlc with a shortcut to this batch file. unfortunately this will open a consome window, of course.




回答2:


First, I would double check that no events are logged for this application.

If there are none, you can create a task in Task Scheduler then go into the event log, then create a custom view for the event.

After the event is created, you can right click your new custom event, then click "attach a task to this event"

The task for the event would be to run the exe.

Below is a link that describes how to create the custom view:

http://www.techrepublic.com/article/simplify-the-windows-87-event-viewer-by-creating-custom-views/

You would need to specify either the "By Source"or By "Event ID" option and see if your application appears in those options.

If the applciation doesn't appear in those options and the above doesn't work you may want to check the registry setting for the application and may need to check if there is a key for event logging.



来源:https://stackoverflow.com/questions/25438820/run-a-windows-command-script-when-a-specific-program-opens-closes

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