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!
Run scripts as administrator? Topic is solved
Re: Run scripts as administrator? Topic is solved
Press Alt+Enter on AutoHotkey.exe -> Compatibility -> Run this program as administrator.
You can also associate .ahk extension with the application if you want
You can also associate .ahk extension with the application if you want
Re: Run scripts as administrator?
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.
Re: Run scripts as administrator?
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).
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).
Re: Run scripts as administrator?
works perfectly thanks for this!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.
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.