Simple: End a Process--not working?
Simple: End a Process--not working?
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.
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: Simple: End a Process--not working?
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.
P.S. If you summon any daedra, I won't hesitate to ban you.
Re: Simple: End a Process--not working?
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.
Thanks for the suggestions. I'll see how it goes.
Don't worry, I'm not a conjurer.If you summon any daedra, I won't hesitate to ban you.
Re: Simple: End a Process--not working?
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...
Re: Simple: End a Process--not working?
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...
Re: Simple: End a Process--not working?
When I use the window name with winkill (in english version "Calculator", I would guess), I am able to close the calculator in Win10.
Re: Simple: End a Process--not working?
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...
Re: Simple: End a Process--not working?
Odd. So far, everything I've tried to close via window title has closed with WinKill except the mail app.
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: Simple: End a Process--not working?
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.
Re: Simple: End a Process--not working?
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.
I would still like to hear other people's experience with closing apps on W10. If you feel like dropping a line.
Re: Simple: End a Process--not working?
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.
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: Simple: End a Process--not working?
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.
Edit: you can also achieve system status by creating a service, executing it, then removing it. Very important to remove it afterwards.
Re: Simple: End a Process--not working?
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.
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.
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: Simple: End a Process--not working?
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.Masonjar13 wrote:you can have AHK impersonate a process
Edit: I don't believe the TI elevation works on W10, so you'll probably have to make your own method for it.
Re: Simple: End a Process--not working?
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.
Re: Simple: End a Process--not working?
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?
Re: Simple: End a Process--not working?
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:
Didn't even have to run it elevated. (More info: https://docs.microsoft.com/en-us/powers ... op-process)
Hope this helps...
Code: Select all
psScript =
(
stop-process -name mshta
)
RunWait PowerShell.exe -Command &{%psScript%} ,, hide
Hope this helps...
Re: Simple: End a Process--not working?
Thanks for sharing, nice post! Post really provice useful information!
Who is online
Users browsing this forum: Google [Bot], NinjoOnline and 228 guests