0

I've been coding python for some time now, and I'd like to code a program that would automatically close an app when it opens. For example, I would like a to code something that would automatically close steam or something similar when it opens. How would I do this? I've looked over the internet and can't find my answer. Is this even something to do in python?

  • Check out this thread: https://stackoverflow.com/questions/2940858/kill-process-by-name. If you are on Windows open the Task Manager, switch to Details and check the name of the process you wish to kill (e.g. steam.exe). – ewz93 Aug 04 '22 at 19:26
  • Some combination of [triggering your Python script when a certain process starts](https://superuser.com/questions/745318/how-to-start-a-program-when-another-one-is-started) and [killing said process](https://stackoverflow.com/questions/6278847/is-it-possible-to-kill-a-process-on-windows-from-within-python). If you're on Windows, you're probably better off using something with a lighter runtime than Python (i.e, PowerShell.) – thariqfahry Aug 04 '22 at 19:28

1 Answers1

0

You could let python run in the background and check every couple of seconds if a process exists. A list of running processes shows you the name of the program that you want to close. You cannot use a PID because it changes every time you restart the program. See this thread to close a process. If you're running Linux, you can easily run python in the background like this: python main.py &

Or you can create a Linux service to run python: https://medium.com/codex/setup-a-python-script-as-a-service-through-systemctl-systemd-f0cc55a42267