Issues killing a process Topic is solved

Ask gaming related questions (AHK v1.1 and older)
LegzRwheelz
Posts: 56
Joined: 04 Nov 2019, 17:46

Issues killing a process

Post by LegzRwheelz » 15 Aug 2022, 06:34

Hey all, I am pulling my hair out over this one. I have an HTPC, I have used AHK extensively to achieve many tasks, essentially eliminating the mouse in favor of my Harmony Universal Remote. It is a godsend to me in achieving a console-like experience. I have a script that continuously runs in my system tray from boot that handles all of my hotkeys which includes launching games, programs, utilities, Google Chrome to hiding my cursor, changing my cursor, closing apps freeing, killing apps that have hung, freeing up system resources etc. I have many hotkeys for many settings and everything works great except this one really annoying issue...

In my script I have a hotkey that launches Chrome and YouTube TV in kiosk mode as well as a tiny program from Steam called "Controller Companion", which gives me control with my XBOX controller. That part works fine, everything loads as it should. It is when exiting the script, Controller Companion refuses to close, Chrome closes as it should but CC is steadfast in running in the system tray. I have tried winkill, process,close and winclose with the ahk_exe process name but it will not terminate CC. It is not a program that runs as a service and I can close it from task manager as well as right-clicking>close on the system tray icon.

Window Spy provides the following information:

Code: Select all

ahk_class HwndWrapper[ControllerCompanion.exe;;20b9cbd1-bce2-4c31-abf3-c5e67ee37b9b]
ahk_exe ControllerCompanion.exe
ahk_pid 31016
I have used the handy Window Spy function to get window and game information for all of my hotkeys but no matter what I use to try to kill the process, nothing happens.

Currently I am just testing on a single ahk script that I double-click, this is my current attempt (not my only though):

Code: Select all

if WinExist (ahk_exe ControllerCompanion.exe)
winclose
exitapp
If I can just get it to kill the process, I can take it from there...so...to whomever decides to help, I appreciate it greatly, so will my OCD 🤪🥴🤭

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Issues killing a process

Post by mikeyww » 15 Aug 2022, 06:58

Function names are always followed by ( rather than a space. Functions use :arrow: expressions, such as a quoted string, variable name, etc.

Code: Select all

winTitle = ahk_exe ControllerCompanion.exe
If WinExist(winTitle)
 WinClose
ExitApp
Some processes may require admin rights or UI access to close them. In other cases, you can force a TASKKILL.

A simple way to test whether your WinExist works is to display the value returned by the function.

LegzRwheelz
Posts: 56
Joined: 04 Nov 2019, 17:46

Re: Issues killing a process

Post by LegzRwheelz » 15 Aug 2022, 20:15

mikeyww wrote:
15 Aug 2022, 06:58
Function names are always followed by ( rather than a space. Functions use :arrow: expressions, such as a quoted string, variable name, etc.

Code: Select all

winTitle = ahk_exe ControllerCompanion.exe
If WinExist(winTitle)
 WinClose
ExitApp
Some processes may require admin rights or UI access to close them. In other cases, you can force a TASKKILL.

A simple way to test whether your WinExist works is to display the value returned by the function.
Hi, I was really hoping you would be the one that replies. You have helped me a few other times in the past and the posts that I have read seeking answers where you replied, have gotten me the results that I sought. So thank you for replying and explaining the formatting that is necessary to achieve my desired results. I have updated my always-on script to reflect this 'new' method so my other 'process,close [app name.exe]' (approx 12 different apps) that are tied to my '+escape' hothey close in a cleaner manner. Unfortunately this still hasn't solved my issue. Controller Companion remains persistent in running in the system tray. Even the 'process,close controllercompanion.exe' method fails to work, I know this the most aggressive manner in killing a process but it fails in doing so.

Any other ways? I am thinking i may create a batch file with 'taskkill' and convert it to an invisible prompt exe using bat-to-exe and just run it with my hotkey, I don't want to do it this way but suppose I am going to have to go this route if nothing else works.

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Issues killing a process  Topic is solved

Post by mikeyww » 15 Aug 2022, 20:18

You can test a Windows batch file with TASKKILL. If it works, you can simply use it in AHK with a Run command. Some processes may require admin rights or UI access to close them, but TASKKILL with the "force" parameter usually works.

Code: Select all

proc = notepad.exe
RunWait, TASKKILL /F /IM %proc% /T,, Hide

LegzRwheelz
Posts: 56
Joined: 04 Nov 2019, 17:46

Re: Issues killing a process

Post by LegzRwheelz » 15 Aug 2022, 20:41

deleted
Last edited by LegzRwheelz on 15 Aug 2022, 20:48, edited 1 time in total.

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Issues killing a process

Post by mikeyww » 15 Aug 2022, 20:47

As I mentioned a couple of times, you can try running as admin to see if that helps.

LegzRwheelz
Posts: 56
Joined: 04 Nov 2019, 17:46

Re: Issues killing a process

Post by LegzRwheelz » 15 Aug 2022, 20:47

mikeyww wrote:
15 Aug 2022, 20:18
You can test a Windows batch file with TASKKILL. If it works, you can simply use it in AHK with a Run command. Some processes may require admin rights or UI access to close them, but TASKKILL with the "force" parameter usually works.

Code: Select all

proc = notepad.exe
Run, TASKKILL /F /IM %proc% /T,, Hide
THanks again for replying, so I created my batch file using

Code: Select all

taskkill /f /im ControllerCompanion.exe
and I get the following error

Code: Select all

ERROR: The process "ControllerCompanion.exe" with PID 31212 could not be terminated.
Reason: Access is denied.
So I tried a few things
1) I checked where steam has it installed , it was installed to my C drive (which is where windows is installed). I figured that may have something to do with it and moved it to my H drive, which is where my steam library is located. Still no dice.
2) I took ownership by editing access on the security tab of properties as well as trying the take ownership right-click context menu reg 'hack'. I am the owner of the folder and all files within it and still I get the error noted above.

I will try your fancier cmd suggestion and report back.

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Issues killing a process

Post by mikeyww » 15 Aug 2022, 20:56


LegzRwheelz
Posts: 56
Joined: 04 Nov 2019, 17:46

Re: Issues killing a process

Post by LegzRwheelz » 15 Aug 2022, 20:59

mikeyww wrote:
15 Aug 2022, 20:18
You can test a Windows batch file with TASKKILL. If it works, you can simply use it in AHK with a Run command. Some processes may require admin rights or UI access to close them, but TASKKILL with the "force" parameter usually works.

Code: Select all

proc = ControllerCompanion.exe
RunWait, TASKKILL /F /IM %proc% /T,, Hide
Great! This works!!! I run as admin and it kills the process, finaly. My next question is how to run this script with elevated permissions (as administrator) without right-click>run as admin?

Edit: so I added

Code: Select all

if !A_IsAdmin
    Run, % "*RunAs " (A_IsCompiled ? "" : A_AhkPath " ") Chr(34) A_ScriptFullPath Chr(34)
at the top of my script and it is working perfectly. THANK YOU SOOO MUCH!!!!

Post Reply

Return to “Gaming Help (v1)”