0

I want to know how can we run a bat file when a specific application is opened?

Eg: I would like to run a bat file whenever mspaint is opened.

I have successfully performed this in Windows 7 and Windows 10 using Task Scheduler. But the task scheduler available in Win Xp is very basic.

JoDG
  • 1,317
  • 8
  • 18
Sree
  • 11
  • 3

1 Answers1

0

You could use another batch file that runs on startup of windows. use while loop with an appropriate sleep to detect when Paint.exe runs.
then you could write more commands to do anything you want. For example, as you said, you could run another batch file...
I found this solution by an investigation of these topics:

Syntax for a single-line Bash infinite while loop
How to check if a process is running via a batch script
Batch program to to check if process exists

  • Does running such a script in the background slow down the PC? – Sree Aug 28 '18 at 09:19
  • @Sree No, it does not. you need to add some sleep in the loop. like someone has done in the post: https://stackoverflow.com/questions/1289026/syntax-for-a-single-line-bash-infinite-while-loop the post shows how to add sleep. – Vahid Asbaghi Aug 28 '18 at 09:55
  • Another way is to write a program in low-level programming languages like C++. To inform about a process starting to run, there are some nice ways. Search the web with Create Process keyword. There are some nice examples and solutions. – Vahid Asbaghi Aug 28 '18 at 10:26