-1

I'm self-studying python so I'm very inexperienced so I hope you guys can help The specific problem is: I'm building a voice communication virtual assistant, I have managed to open the application by voice, but can't write the code to close a running application with a specific name. I tried using the command send_keys('%{F4}') and doesn't seem to get the desired result So is there any other way?

    elif "discord" in you:
    app =  application.Application()
    app.start("C://Users//admin//AppData//Local//Discord//Update.exe --processStart Discord.exe")
    robot_brain = "runing Discord"
elif you == " exit discord":
    send_keys('%{F4}') # close an active window with Alt+F4
    robot_brain = " exit discord"
MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • Regarding `update.exe`... No GUI commands should be automated with built-in module `subprocess`. pywinauto is for GUI automation only, i.e. for complicated cases. Command line automation is much easier, even batch script or PowerShell could be enough in many cases. So even Python may be not necessary. – Vasily Ryabov Feb 20 '23 at 07:41
  • And at the second hand, `app.close(soft=False)` could be used, or with `soft=True` if you don't want hard termination. – Vasily Ryabov Feb 20 '23 at 07:43

2 Answers2

1

You can also use taskkill.

proc = subprocess.Popen(['taskkill', '/f', '/im', 'program_name.exe'])
assert proc.wait() == 0
Lima
  • 257
  • 1
  • 8
0

Hello, im not too sure what the app is (in your code) but you can use the os module to start files and to start a exe and to exit it example

import os
os.system("C:/Users/username/Downloads/main.exe")

this starts the file (use startfile instead of system if you want to open like a txt or anything not exe file)

their is alot of way to close it heres some usefull links

How to Close a program using python? https://docs.python.org/3/library/os.html#os.kill