autohotkey_在Windows 7或Vista中为AutoHotkey脚本添加“以管理员身份运行”

autohotkey

autohotkey

As regular readers know well, I’m a huge fan of using AutoHotkey  to automate my entire computing experience… but in Windows 7 and Vista there’s a serious limitation since you can’t run a script as Administrator by default. This means that your hotkeys can’t interact with windows running in Admin mode… so how do we get around this?

普通读者都知道,我非常喜欢使用AutoHotkey来自动化我的整个计算体验……但是在Windows 7和Vista中存在一个严重的限制,因为默认情况下您无法以管理员身份运行脚本。 这意味着您的热键不能与以管理员模式运行的Windows交互……那么我们如何解决这个问题?

There are three solutions to this problem:

解决此问题的方法有三种:

  • Completely Disable UAC – Not the best solution for security purposes, but it works.

    完全禁用UAC –不是出于安全目的的最佳解决方案,但它可以工作

  • Compile your script to an executable.

    将脚本编译为可执行文件。
  • Hack the registry and add “Run as Administrator” to the context menu.

    入侵注册表,然后在上下文菜单中添加“以管理员身份运行”。

Compile Script as Executable

将脚本编译为可执行文件

All you have to do is right-click on the script, choose “Compile Script”…

您要做的就是右键单击脚本,选择“编译脚本”…

image

And now you can run the executable version as administrator:

现在,您可以以管理员身份运行可执行版本:

image

This isn’t the perfect solution, however. I edit my script all the time, so having to recompile each time I make an edit… would get annoying.

但是,这不是完美的解决方案。 我一直在编辑脚本,因此每次进行编辑时都必须重新编译……会很烦人。

Manual Registry Hack for AutoHotkey “Run as Administrator”

AutoHotkey的手动注册表黑客“以管理员身份运行”

Open up regedit through the start menu search or run box, and then browse down to the following key:

通过开始菜单搜索或运行框打开regedit,然后向下浏览至以下键:

HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell

HKEY_CLASSES_ROOT \ AutoHotkeyScript \ Shell

image

Right-click on “Shell” on the left-hand side and create a new key called “runas”, then create a key called “Command” below it. Then create or set the following two values on the right-hand side, adjusting the path if necessary.

右键单击左侧的“ Shell”,然后创建一个名为“ runas”的新键,然后在其下方创建一个名为“ Command”的键。 然后在右侧创建或设置以下两个值,并在必要时调整路径。

Name Value
(Default) “C:\Program Files\AutoHotkey\AutoHotkey.exe” “%1” %*
IsolatedCommand “C:\Program Files\AutoHotkey\AutoHotkey.exe” “%1” %*
名称
(默认) “ C:\ Program Files \ AutoHotkey \ AutoHotkey.exe”“%1”%*
独立命令 “ C:\ Program Files \ AutoHotkey \ AutoHotkey.exe”“%1”%*

The default key should already be there, just need to set the value.

默认**应该已经在那里,只需要设置值即可。

Now when you right-click on an AutoHotkey script, you’ll see the option to Run as Administrator:

现在,当您右键单击AutoHotkey脚本时,您将看到以管理员身份运行的选项:

image

Download Registry Hack

下载注册表黑客

Download, extract, and double-click on the AdminAutoHotkey.reg to enter the information into the registry. There’s also a removal script included.

下载,解压缩并双击AdminAutoHotkey.reg,以将信息输入注册表。 还包括一个删除脚本。

Note that this registry hack will only work if you installed AutoHotkey into the default location, otherwise you’ll have to modify the paths.

请注意,只有在将AutoHotkey安装到默认位置后,此注册表黑客才会起作用,否则,您将不得不修改路径。

Download AdminAutoHotkey Registry Hack

下载AdminAutoHotkey注册表黑客

翻译自: https://www.howtogeek.com/howto/windows-vista/add-run-as-administrator-for-autohotkey-scripts-in-windows-vista/

autohotkey