Run scripts as administrator? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Win10isAwful

Run scripts as administrator?

08 Aug 2016, 16:30

I recently "upgraded" to Windows 10, and now I'm running into the frustrating problem of scripts not interacting with other programs/apps unless the script is run as administrator.

In the past, I've always kept my scripts on my desktop as .txt, and when I want to execute them, I right-click, Open With, and select AHK. This doesn't work now, since that action will not run the script as administrator.

How can I set up my computer such that I can quickly run scripts as administrator?

Thanks for your help!
VarunAgw
Posts: 24
Joined: 05 Jan 2016, 11:51
GitHub: VarunAgw

Re: Run scripts as administrator?

08 Aug 2016, 16:34

Press Alt+Enter on AutoHotkey.exe -> Compatibility -> Run this program as administrator.

You can also associate .ahk extension with the application if you want
User avatar
Capn Odin
Posts: 1308
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: Run scripts as administrator?

08 Aug 2016, 16:36

Try changing the extension to .ahk, if that dossne't work you will need to change the registry, it can be done using regedit, search for it in the start menu.
Please excuse my spelling I am dyslexic.
lexikos
Posts: 7085
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Run scripts as administrator?  Topic is solved

08 Aug 2016, 20:19

I would not recommend changing compatibility settings of AutoHotkey.exe.

Running as administrator is not the only solution; see the FAQ: How do I work around problems caused by User Account Control (UAC)?

A script can also run itself as admin by using Run *RunAs "%A_AhkPath%" "%A_ScriptFullPath%". (A_AhkPath is usually optional if the script has the .ahk extension.) You would typically check if not A_IsAdmin first.

If you want a "Run as administrator" option for txt files, you can try copying the Shell\RunAs\Command subkey of HKCR\AutoHotkeyScript into the text file key (usually HKCR\txtfile), but I think you're better off just using the .ahk extension. If you want Edit to be the default (for double-click), you can change the default value of HKCR\AutoHotkeyScript\Shell to Edit (it is usually Open).
DRocks
Posts: 559
Joined: 08 May 2018, 10:20

Re: Run scripts as administrator?

01 Oct 2018, 12:11

lexikos wrote:A script can also run itself as admin by using Run *RunAs "%A_AhkPath%" "%A_ScriptFullPath%". (A_AhkPath is usually optional if the script has the .ahk extension.) You would typically check if not A_IsAdmin first.
works perfectly thanks for this!

Code: Select all

#SingleInstance Force
SetWorkingDir %A_ScriptDir%
if not A_IsAdmin
	Run *RunAs "%A_ScriptFullPath%" ; (A_AhkPath is usually optional if the script has the .ahk extension.) You would typically check  first.

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, AlexL, BGM, evilmanimani, jarhead, keylo, mikeyww, smogmanus and 51 guests