2 minute read

March 2023 Update: I’ve found another solution that I prefer over this one. See this post for details.

A while back I posted about AutoHotkey not being able to interact with Windows 8 windows and other applications that were Ran As Admin. My solution was to run your AutoHotkey (AHK) script as admin as well, and I also showed how to have your AHK script start automatically with Windows, but not as an admin. Afterwards I followed that up with a post about how to get your AHK script to run as admin on startup, so life was much better, but still not perfect.

Problems with running your AHK script as admin

  1. You may have to deal with the annoying UAC prompt every time you launch your script.
  2. Any programs the script launches also receive administrative privileges.

#1 is only a problem if you haven’t set your AHK script to run as admin on startup as I showed in my other blog post (i.e. you are still manually launching your script) or you haven’t changed your UAC settings to never prompt you with notifications (which some companies restrict) (see screenshot).

UAC Never Notify

#2 was a problem for me. I use AHK Command Picker every day. A lot. I’m a developer and in order for Visual Studio to interact with IIS it requires admin privileges, which meant that if I wanted to be able to use AHK Command Picker in Visual Studio, I had to run it as admin as well. The problem for me was that I use AHK Command Picker to launch almost all of my applications, which meant that most of my apps were now also running as an administrator. For the most part this was fine, but there were a couple programs that gave me problems running as admin. E.g. With PowerShell ISE when I double clicked on a PowerShell file to edit it, instead of opening in the current (admin) ISE instance, it would open a new ISE instance.

There is a solution

Today I stumbled across this post on the AHK community forums. Lexikos has provided an AHK script that will digitally sign the AutoHotkey executable, allowing it to interact with applications running as admin, even when your AHK script isn’t.

March 2023 Update: I’ve found that this solution no longer works. I’m not certain if the problem is something with my local machine, or an update to newer versions of AutoHotkey. If you don’t want to use my new preferred solution, let me know if this one still works for you in the comments.

Running his script is pretty straight forward:

  1. Download and unzip his EnableUIAccess.zip file; you can also get it here.
  2. Double-click the EnableUIAccess.ahk script to run it, and it will automatically prompt you.
  3. Read the disclaimer and click OK.
  4. On the Select Source File prompt choose the C:\Program Files\AutoHotkey\AutoHotkey.exe file. This was already selected by default for me. (Might be Program Files (x86) if you have 32-bit AHK installed on 64-bit Windows)
  5. On the Select Destination File prompt choose the same C:\Program Files\AutoHotkey\AutoHotkey.exe file again. Again, this was already selected by default for me.
  6. Click Yes to replace the existing file.
  7. Click Yes when prompted to Run With UI Access.

That’s it. (Re)Start your AHK scripts and they should now be able to interact with Windows 8 windows and applications running as admin :-)

This is a great solution if you want your AHK script to interact with admin windows, but don’t want to run your script as an admin.

Did you know

If you do want to launch an application as admin, but don’t want to run your AHK script as admin, you can use the RunAs command.

I hope you found this article useful. Feel free to leave a comment.

Happy coding!

Comments

Stephen Wille

Thanks for the post. I love AHK too, and am also on a corporate win8 machine running VS2012….ugh! If you have any ideas on how to customize VS2012’s code completion, formatting, and hot keys, please post them. This has become a huge pain point.

deadlydog

@Stephen Wille Hey Stephen, I’m not sure what you mean. If you are running VS as admin, then the trick I mention in this post should allow AHK to interact with VS. If you are not running VS as admin, then everything should just work without doing this trick.

Are you asking how to customize VS 2012’s code completion, formatting, and shortcut keys natively in VS? or how to implement your own with AHK? You can customize all of the VS shortcut keys in the Tools->Options->General->Keyboard menu, and specify a few rules around code completion and formatting too in the Tools->Options menus, but not too many. If you really want to customize the code completion and formatting rules, tools like ReSharper give you much more control.

Stephen Wille

@deadlydog

No prob running AHK, and so far, that’s my main tool for making VS easier to use.
I really like ReSharper, and the folks who make it also make my preferred IDE, IntelliJ IDEA. Unfortunately, corporate rules prevent me from running it on my laptop. I would like to implement ReSharper like functionality natively, or though open source plugins or AHK. So far, I haven’t found VS to have much flexibility when it comes to customization, and online resources haven’t been directly on point either. So any help into how to wrest fully control of these things from VS is appreciated.

Matteo Sacco

thank you so much you, I use CapsLock to launch task view in Win10 just about all the time, since i’m also a mac user and I constantly use mission control. And not being able to use it in Virtual Studio was really frustrating.

HaveSpacesuit

Amazing! Half of my apps are always in Admin mode, so it was a pain to have to click out of them to use my scripts. Thanks to those who put time into it.

eefias

Doesn’t work for me :(. After running the script, when I run Autohotkey.exe, I get an error “A referral was returned from the server.”

[OK]

eefias

Never mind. Found out the issue. If you have setup Fiddler for decrypting HTTPS, for some reason, the cert installed by this script becomes issued by the Fiddler’s non-trusted authority, which causes the error I mentioned above. Once I removed Fiddler’s cert, it worked :)

eefias

Hey guys, With this fix, my admin mode apps now respect the hotkeys. One strange issue : After a hotstring/key runs, I need to hit the Win key to “end” it. For example, I have a hotkey (Win + 2) to activate all Chrome windows to bring them into the foreground. When I press Win+2, the Chrome windows get activated, but if I type any key after that, weird windows pop up. I have to hit the Windows key to disable this every time.

Leave a Comment

Your email address will not be published. Required fields are marked *

Loading...