Jump to content

Recommended Posts

Posted (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 by Bob Coleman
Add info about increasing length of sleep.
Posted

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...

Posted (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 by Bob Coleman
Posted (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 by Bob Coleman
Added line about interest and trouble.
Posted (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 by Bob Coleman
Added discovery that Task Scheduler doesn't close.
Posted (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 by bobomb

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...