Running a command in an elevated prompt

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bobmac1547
Posts: 5
Joined: 05 Dec 2015, 21:05

Running a command in an elevated prompt

26 Mar 2017, 19:53

I'm using one "Master Script" where I put little ditties like my email addy, my snailmail addy, phone number, etc. into different parts of the script under ^+S:: or ^+f:: and so forth. They are all basically SEND commands. All works well.

Now I'm trying to add something to that master script which is the first executable for me. I want to run an elevated command prompt (as Admin) and run the command "powercfg -requests" Nothing is working. I get the error box pointing to the line: "Run Runas, cmd.exe"

Here's what I have

Code: Select all

^+s::
Runas, LogonName, Password
Run Runas, cmd.exe
Send {raw2} powercfg -requests
Send {enter}
Runas
return
Can someone help this newbie who can't program his way out of a wet paper bag? :|
I measure a good day by how little I fell behind
Once you've seen one Parkinson's patient, you've seen one Parkinson's patient. http://parkinson.org
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Running a command in an elevated prompt

26 Mar 2017, 21:02

I'd read through the Run document page, and check the section on *RunAs.
https://autohotkey.com/docs/commands/Run.htm#RunAs

I'm not too sure what output you are expecting from powercfg -requests but you could try something like this:

Code: Select all

^+s::
Runas, LogonName, Password
Run *RunAs %comspec% /c powercfg -requests & pause ; If you don't need it to leave the window open remove the & pause
Runas
return
*Edit
You may not need the Runas, LogonName, Password and the following Runas if you are already an admin, it should only be needed if you need to run as a different user than is running the script.
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Running a command in an elevated prompt

26 Mar 2017, 22:22

Also see the FAQ, specifically the one about UAC.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Draken, oktavimark, Spawnova, william_ahk and 274 guests