Bob Coleman Posted November 26, 2021 Posted November 26, 2021 (edited) I have a script containing only the following two lines: sleep(250) send('!{F4}') I invoke this via a hot key in another program. I no longer remember the reason for the sleep statement. In general, invoking this script via the hotkey causes the active window to close. However when that window is the Windows Task Manager, it doesn't close. I've added temporarily added a MsgBox command at the top of the script. I get the message box even when the active window is Task Manager. but the window doesn't close. Increasing the length of the sleep doesn't help either, Yet if Alt + F4 is entered on the keyboard, Task Manager does close. Edited November 26, 2021 by Bob Coleman Add info about increasing length of sleep.
JockoDundee Posted November 26, 2021 Posted November 26, 2021 It’s because task manager is protected from manipulation unless you have elevated privileges. Use #RequireAdmin at the top of your program and try again. Code hard, but don’t hard code...
ad777 Posted December 3, 2021 Posted December 3, 2021 try this code: WinActivate("Windows Task Manager");;wait for task manager to active Send("!");;send ALT key Send("!{F4}");send F4 key Exit none
Bob Coleman Posted December 9, 2021 Author Posted December 9, 2021 (edited) Thanks for the responses and sorry for my delayed response. I thought, apparently incorrectly, that Follow topic would cause me to get an email if there was any response to me. The proposed solution involving explicitly waiting for Task Manager doesn't change the behavior at all. The proposed solution of using #RequireAdmin works, but at the cost of responding to a UAC prompt not only for Task Manager, but for everything else also. Clearly a case of "cure worse than disease". Edited December 9, 2021 by Bob Coleman
ad777 Posted December 9, 2021 Posted December 9, 2021 (edited) idid post code here before but srry this code not for ya but above code for ya, Edited December 10, 2021 by ad777 none
Bob Coleman Posted December 10, 2021 Author Posted December 10, 2021 (edited) I replaced my original two lines of code with all the above. It doesn't seem to do anything to Task Manager or anything else. Thanks for the interest, but this is clearly more trouble than it's worth except as an academic exercise. Edited December 10, 2021 by Bob Coleman Added line about interest and trouble.
Bob Coleman Posted December 10, 2021 Author Posted December 10, 2021 (edited) The "more trouble than it's worth" aside the mention above by JockoDundee that Task Manager has some protected status and that #RequireAdmin may be required and my response that that worked but is a "cure worse than the disease" because it causes a UAC prompt on every invocation nudged me to try a way to avoid UAC prompts that I read about somewhere, sometime years ago. Obviously, other filenames could be used, but for ease of description I'll use mine in this case. The two lines of code shown in my initial post were originally in a file named close_window.au3. I renamed this to close_window_2.au3 and created a new close_window.au3 containing runwait('schtasks' & ' ' & '/RUN' & ' ' & '/TN "Close Window"','',@SW_MINIMIZE) Now close_window.au3 runs a task defined in Task Scheduler named Close Window. That task simply starts the program close_window_2.au3 with highest privileges. Now my hot key which runs close_window.au3 does cause closing of whatever window receives the Alt+F4 without a UAC prompt whether that window is Task Manager or something else, but ... I now have to decide whether working on Task Manager is worth slower response and a screen flicker before the affected window closes. Sigh! It still doesn't close Task Scheduler! Edited December 10, 2021 by Bob Coleman Added discovery that Task Scheduler doesn't close.
bobomb Posted December 10, 2021 Posted December 10, 2021 (edited) @Bob Coleman Have you tried? #RequireAdmin RunWait('cmd /c taskkill /IM ' & '"' & 'taskmgr.exe' & '"' , @WorkingDir, @SW_HIDE) Edited December 10, 2021 by bobomb
Bob Coleman Posted December 11, 2021 Author Posted December 11, 2021 22 hours ago, bobomb said: @Bob Coleman Have you tried? #RequireAdmin RunWait('cmd /c taskkill /IM ' & '"' & 'taskmgr.exe' & '"' , @WorkingDir, @SW_HIDE) No and I probably won't. What I'm interested in is something that kills/closes everything else and also Task Manager, not a special case designed to only kill Task Manager.
bobomb Posted December 11, 2021 Posted December 11, 2021 (edited) @Bob Coleman I was under the impression the method you are using worked on everything except task manager? You could just check to see if its task manager, if not business as usual if so this one line?... It is, however, cmd shell and not AutoIT3.. I understand you are looking for a unified solution.. At least with this you will have a last resort to "make it work" if you need to... Just as a side note: This does kill everything else and task manager if requested to.. EDIT: You would need #RequireAdmin for this anyway so I dont think it would work if you are worried about UAC prompts regardless.. Best of luck.. Edited December 11, 2021 by bobomb
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now