Simple: End a Process--not working?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Simple: End a Process--not working?

11 Aug 2017, 22:06

Does anyone else have issues ending processes with AHK 1.1.26.01 and W10 x64? Maybe I'm being messed with, but I cannot end a process. I haven't tried many--mind you, I keep trying the same few--but they never close. I've tried all AHK functions: Process, WinClose, WinKill, nothing works. So next I tried the "DestroyWindow" function from the API. Doesn't work. It returns the error 5 - "Access is Denied". That is by trying to close Calculator.exe. I've also tried closing the Windows Photos app and windows settings app, both with the same access is denied error. If someone could just run a simple script to close one of those processes on a W10 x64 Creator's Update build, I'd appreciate it.
User avatar
Masonjar13
Posts: 1075
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Simple: End a Process--not working?

11 Aug 2017, 23:13

There's always one issue or another when Windows releases a major update, I've noticed. But it appears that the process you're trying to terminate has higher privilege than the script. If you've already tried running as admin, try using PsExec by SysInternals to run as system and try it that way. Related to another recent thread, you might check to see if the running process image names match between AHK and Task Manager/Process Explorer.

P.S. If you summon any daedra, I won't hesitate to ban you. :geek:
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Simple: End a Process--not working?

12 Aug 2017, 10:42

Okay. I'll run as admin first, then try out PsExec as System if admin doesn't work. As far as matching names: I've left that alone for now until I square away this window closing snag. But, DestroyWindow needs the Window Handle, so that's what I'm using right now in my troubleshooting process. I've tried executable, PID and now hwnd.

Thanks for the suggestions. I'll see how it goes.

If you summon any daedra, I won't hesitate to ban you.


Don't worry, I'm not a conjurer. :)
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Simple: End a Process--not working?

12 Aug 2017, 13:09

Well, no dice running as an administrator--ErrorCode 5: Access is Denied. And I couldn't get the script to run as SYSTEM. I can't be the only person running the latest Windows...
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Simple: End a Process--not working?

12 Aug 2017, 15:14

All the windows/processes that I've tested that I'm having trouble closing are those under the "Application Frame Window" class and are tied to "ApplicationFrameHost.exe". But, the process that Windows shows for each of these windows/processes in Task Manager varies. I'm thinking I've stumbled on a Windows 10 thing here. I'm going to keep digging...
User avatar
gregster
Posts: 260
Joined: 30 Sep 2013, 06:48

Re: Simple: End a Process--not working?

12 Aug 2017, 15:22

When I use the window name with winkill (in english version "Calculator", I would guess), I am able to close the calculator in Win10.
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Simple: End a Process--not working?

12 Aug 2017, 19:39

Win10, eh? Alrighty. I'll try the window name then. I never actually tried window names :) --I've tried PID, executable and window handle. Let me try, I'll post back...
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Simple: End a Process--not working?

12 Aug 2017, 19:49

Odd. So far, everything I've tried to close via window title has closed with WinKill except the mail app.
User avatar
Masonjar13
Posts: 1075
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Simple: End a Process--not working?

12 Aug 2017, 21:15

Because this has been a problem as of late, I did a bit of further research. See here and here. Seems to me the best way to solve these issues are to not use the windows store and go in and disallow ApplicationFrameHost from running. You can either find all the startup references to AFH using something like SysInternals Autoruns, and check and disable any related tasks in the task scheduler, or you can take full permission of the file itself and deny rights from anything else running it. Either way may or may not break the Windows apps, not that you need to use them anyway.
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Simple: End a Process--not working?

12 Aug 2017, 22:49

I want to thank gregster and masonjar13. I did some more testing--and I will continue to test over the next day or two--but it seems that closing an app on W10 CU is hit and miss. I was able to close calculator several times using the window title and WinKill (as suggested by gregster), but other times I was not (in the same testing session). I have been able to close most third-party programs with WinClose and the executable. But, not all. Driver Booster wouldn't close. So, I don't know. I've tried all AHK methods, and even more "forceful" methods via the Windows API. Gregster said he didn't have any issues closing the calculator. I do. It's probably something on my end. I may try and see what I can find on ApplicationFrameHost.exe.

I would still like to hear other people's experience with closing apps on W10. If you feel like dropping a line.
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Simple: End a Process--not working?

14 Aug 2017, 20:24

I've noticed that even the Windows Command Line function "TaskKill" won't close some processes without the /F switch. It says it send the termination notice, but the processes don't close.
User avatar
Masonjar13
Posts: 1075
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Simple: End a Process--not working?

14 Aug 2017, 20:56

These are all parented by AFH, yes? Check who/what owns the process and who has rights to access the file itself. You can give yourself all privileges to the file, but that may cause a security issue, if you care about that. Alternatively, you can have AHK impersonate a process, though I never had the time to set up the code for it. See CreateProcessWithTokenW. Depending on the owner, you may need AHK to be running as system first, which I think you can do with CreateProcessAsUser, or PsExec. If you get those written up in AHK, I'd very much like to see!

Edit: you can also achieve system status by creating a service, executing it, then removing it. Very important to remove it afterwards.
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Simple: End a Process--not working?

15 Aug 2017, 19:02

Yep, ApplicationFrameHost is the most direct executable associated with them. All Groups except "Trusted Installer" have "Read & execute" and "Read" rights to ApplicationFrameHost.exe. But that's pretty typical for files in System32. System does not have full control, so I'm thinking running as System won't make much of a difference. I can close AFH through Task Manager with no problems. It starts back up when you launch a executable that relies on it, or give it about 10 minutes and it starts on it's own. I'll look deeper using your suggestions and the functions you linked to. Thanks again.

I'm just wondering how to force close all applications via the process associated with them in Task Manager? If I can't figure anything else, I can always call the Command Line through AHK and use Taskkill with the /f switch. I just don't like it that way. OCD, I suppose.
User avatar
Masonjar13
Posts: 1075
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Simple: End a Process--not working?

15 Aug 2017, 19:22

Masonjar13 wrote:you can have AHK impersonate a process

This includes TrustedInstaller. Meaning, you may allow your process to act on behalf of TI. There are publicly-available compiled (not sure if the source is around) AutoIt scripts around for doing exactly this. Though, to impersonate TI, you will first need to run as System. So, Admin > System > TI is the elevation order.

Edit: I don't believe the TI elevation works on W10, so you'll probably have to make your own method for it.
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Simple: End a Process--not working?

16 Aug 2017, 09:25

Well, I started poking around MSDN (and Google) and found ExitProcess and TerrminateProcess. I'm going to play with them some today; see what happens. I wish there was some link that tells me how to duplicate what Microsoft does with Task Manager.
User avatar
Malonn
Posts: 43
Joined: 04 Nov 2016, 09:14

Re: Simple: End a Process--not working?

16 Aug 2017, 10:34

Alright, I have been playing with TerminateProcess and, so far, have had 100% success ending processes. I've found that some of the "Access Denied" stuff I was getting had to do with Process Security and Access Rights. I'm wondering if there is something going on with AHK and Processes in regards to that?
RickC
Posts: 142
Joined: 27 Oct 2013, 08:32

Re: Simple: End a Process--not working?

09 Sep 2017, 11:18

Have you tried wrapping PowerShell's stop-process cmdlet? I was having the same problems closing an HTA window and even TASKKILL /F wouldn't do it. In the end I used the following:

Code: [Select all] [Download] GeSHi © Codebox Plus

psScript =
(
stop-process -name mshta
)

RunWait PowerShell.exe -Command &{%psScript%} ,, hide

Didn't even have to run it elevated. (More info: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/stop-process)

Hope this helps...

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Class1, hotkeyguy, KumaKun, Noesis and 50 guests