Jump to content

Trying to use the ALT key


Recommended Posts

Good day all,

I'm trying to use the drop down menu in Task Manager to start a new task (i.e. Powershell). End goal is to have a script(s) to run windows updates. I've got everything to work, except running Powershell as an admin. Even when I'm logged in as an admin every method except this one has that "Do you want to allow this program to make changes to your computer" box.

Anyway, I've written this script (yes, it's very basic I know, it's been several decades since I've tried to do anything with coding) it opens the Task Manager, but nothing I've tried gets it to do the Alt+f needed to open the file menu.

;trying

Sleep(2000)

; Opens powershell as admin

;send cntrl shift escape
Send("^+{ESC}")
Sleep(3000)

;press alt F to open file menu

Send("{ALTDOWN}")
Sleep(1000)
Send("f")
Sleep(1000)
Send("{ALTUP}")
Sleep(1000)

;press n to start new task
Send("n")
Sleep(1000)

;run powershell as admin
Send("powershell")
Sleep(1000)
Send ("{TAB}")
Sleep(1000)
Send ("{SPACE}")
Sleep(1000)
Send ("{TAB}")
Sleep(1000)
Send ("{ENTER}")
Sleep(1000)

I've tried the "!f" and {ALT}f combo's too, but no joy.

Any advice, suggestions, etc would be appreciated. 

Thank you.

Link to comment
Share on other sites

Unfortunately, your script needs to be elevated to Admin to be able to send ALT+F in the Task Manager.  If you add #RequireAdmin to the top of your script, you will see that it works.  I know that it sort of defeats the purpose though because if your script is elevated when you run Powershell, it will start as Admin.  ;)

If you are an Admin and do not want to get prompted by UAC when you request elevation, then you need to modify the registry or you can change the setting using the Windows GUI.  If you use the GUI, move the setting to "Never Notify"  If you want to make the change programtically, then you can look up the key(s) or you can use the UAC UDF (link below).

 

#RequireAdmin
#include <Constants.au3>

;Launch Task Manager
Send("^+{esc}")
If Not WinWaitActive("[regexptitle:Task Manager]", "", 3) Then Exit MsgBox($MB_ICONERROR, "ERROR", "Timeout occurred waiting for Task Manager")

;Run Powershell as Admin
Send("!fn")
Sleep(500)
Send("Powershell")
Send("{TAB}{SPACE}{TAB}{ENTER}")

https://www.autoitscript.com/forum/topic/158377-user-account-control-uac-udf/

Edited by TheXman
Link to comment
Share on other sites

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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