-4

I want to try to prevent a program from being run with Python. For example, notepad.exe. My idea is the following, but will this work?

import os

i = 0

while i < 1:

    os.system('taskkill /f /im notepad.exe') 
Erick Shepherd
  • 1,403
  • 10
  • 19
Wyren
  • 117
  • 1
  • 4
  • 16

1 Answers1

1

Your solution will work, but it will spawn a lot of console windows one after another. To avoid it you can try this:

>>> import subprocess
>>> from time import sleep
>>> si = subprocess.STARTUPINFO()
>>> si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
>>> while True:
        subprocess.call('taskkill /F /IM notepad.exe', startupinfo=si)
        sleep(1) # delay 1 seconds
mshsayem
  • 17,557
  • 11
  • 61
  • 69