Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

run powershell script in python

You can do this simpily by doing the following:
  
import os

os.cmd('powershell commands/args here')


  ===============================================
  |		   Simple proccess kill script:			|
  ===============================================

# Not a default module: install by doing: 'pip instal psutil'
# or by doing: 'py -m pip install psutil'
import psutil
import os

process = ["Skype.exe"] 
# When adding other proccess to this list, Please add copy the name to the tee
# Other wise it will not find it

while True: # We keep this going forever (You can remove the True loop)
    for procs in process: # We then get the items from the table above
        if procs in (p.name() for p in psutil.process_iter()): # Check for them
            os.system(f'powershell TASKKILL /F /IM {procs}')
            # If the exes from the table is running then we force kill the proc
            # Using powershell (doesnt have to be ps can be just normal CMD)
            # The kill command will print the proccess it killed and the PID
    time.sleep(4) # After, We will then wait 4 seconds before looping again
 
PREVIOUS NEXT
Tagged: #run #powershell #script #python
ADD COMMENT
Topic
Name
7+8 =