 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
M-D-C
Joined: 19 Nov 2009 Posts: 1
|
Posted: Thu Nov 19, 2009 4:59 am Post subject: Sending Keystrokes to Elevated CMD Window |
|
|
I have been trying every which way to send keystrokes through AHK to an elevated CMD window in Windows 7. No problem sending to un-elevated window. Can this be done? Maybe it is prohibited by UAC?
Help greatly appreciated. |
|
| Back to top |
|
 |
tinaa
Joined: 25 Nov 2004 Posts: 47
|
Posted: Thu Nov 19, 2009 6:14 pm Post subject: |
|
|
For an autohotkey script to interact with any elevated application it has to itself be launched as elevated.
There are a number of ways to do this. You can write a simple batch file to run autohotkey.exe with your script as an argument then launch the batch file as administrator. You'll want to use the "start" command to prevent the CMD window from staying open. Something like the following will work:
| Code: | | start "drive:\path\AutoHotkey.exe" "drive:\path\scriptname.ahk" |
You can then right-click on the batch file and select to run as administrator. You can also make a shortcut to this batch file and under properties/compatibility select for it to always launch as administrator. You'll still get a UAC prompt but you can launch with a simple double-click.
If you want to launch without a UAC prompt you can use these tricks:
To load a script at startup with elevation and no prompt: http://blogs.techrepublic.com.com/window-on-windows/?p=616&tag=leftCol;post-635
On-demand with elevation and no prompt:
http://blogs.techrepublic.com.com/window-on-windows/?p=730&tag=rbxccnbtr1
However, you do need to be careful with what you do with your elevated script. Take note that any other application you launch from that script will inherit the elevation (not sure if there's any way to launch a non-elevated process from an elevated script...) so you don't want to be launching your browser... Of course it's probably not hard for a third-party to insert code into your script so it's a potential security issue, although I don't know that autohotkey is sufficiently widely-used as to be a likely target for any realworld malware and you can protect from untrusted users by setting appropriate permissions on the .ahk file.
I've set up my system to run 2 scripts at startup. I have an elevated script that I use for hotkeys that make modifications to windows (sizing, position, etc.) so that they work on elevated windows but the script doesn't have any hotkeys for launching apps. My second script, which runs as a regular user, has all the hotkeys I use for launching apps. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4367 Location: Qld, Australia
|
Posted: Fri Nov 20, 2009 10:08 am Post subject: |
|
|
FYI,
| Chris wrote: | | Code: | if not A_IsAdmin
{
DllCall("shell32\ShellExecuteA", uint, 0, str, "RunAs", str, A_AhkPath
, str, """" . A_ScriptFullPath . """", str, A_WorkingDir, int, 1) ; Last parameter: SW_SHOWNORMAL = 1
ExitApp
} |
Source: Support for UAC |
Also, Compile_AHK can compile a script in such a way that it will automatically request administrative rights (it'll trigger a UAC prompt). |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|