一、简介
这是一个帮助用户自定义ahk文件右键菜单的工具,作者是microbug,维护河许人。对于看不习惯右键菜单中有三个英文菜单和默认编辑器不适应的用户来说是很有作用的。
二、使用帮助
直接下载运行,即上面的界面,如果所见即所得,没有什么不好理解的,如果你有什么建议或者使用不方便、不明白的地方可以在评论区留言。
三、源码
/*
language: chinese simple (中文简体)
coding: UTF-16LE ( utf-8-BOM )
AutoHotkey版本: 1.1 , 2.0alpha
操作系统: Windows
作者: microker(autoahk.com)、microbug(autoahk.com)
私人博客: https://blog.0yi.top
中文学习论坛: https://autoahk.com
脚本发布时间: 2021-1-7
使用方法: 将此文件拖动到autohotkey.exe主程序上运行即可。
脚本说明: 此工具用来修改 AutoHotkey 脚本的右键菜单关联,适用于 AutoHotkey 安装版、绿色版。
程序配置尝试把 AutoHotkey 原版的相关信息写在注册表HKCR主键中(全局配置),
尝试是当前用户否有权操作该键,如果无权操作HKCR键(受限用户),可通过操作注册表HKCU键来实现仅当前用户关联AHK脚本。
脚本原作者:甲壳虫<jdchenjian@gmail.com>(2009年1月21日),作者“兔子”二次修改(2016年04月18日)
两任源作者都不做维护。时隔四年半后,microbug、microker再次修改脚本程序。
由于脚本无法同时兼容1.1版本和2.0版本,此脚本程序暂时分为两个版本发布。
1.1.1.0 用于AHK1.1解压版(绿色版)创建ahk扩展名的快捷方式(不含ahk2),兼容win10系统,在1.1.33.2版本测试通过。
右键菜单增加以管理员身份运行AHK脚本功能,同时增加受限用户安装的醒目提示(全局安装不提示)
2.0.1.0 增加ahk2扩展名支持,以支持ahk2alpha程序。若没有1.1版本程序则同时关联ahk和ahk2扩展名
*/
#NoEnv
#SingleInstance, force
FileEncoding UTF-16
SendMode Input
SetWorkingDir %A_ScriptDir%
AhkDir := A_ScriptDir
Editor := "autoahk.exe"
RegRoot := "HKCU\SOFTWARE\Classes"
; 版本(仅用于显示)
Script_Version=v1.1.1.0
IsLimitedUser:=0
if not A_IsAdmin
IsLimitedUser:=1
; 此处为原作者旧版判断是否是管理员身份运行。本想注释掉,但后来不保险所以最后还是留着了。
RegWrite, REG_SZ, HKCR, .test
if ErrorLevel
IsLimitedUser:=1
RegDelete, HKCR, .test
if ErrorLevel
IsLimitedUser:=1
if IsLimitedUser=0 ; 非受限用户操作HKCR键
{
RootKey=HKCR
Subkey=
}
else ; 受限用户操作HKCU键
{
RootKey=HKCU
Subkey=Software\Classes\ ; <-- 为简化后面的脚本,此子键须以“\”结尾
}
; 检查是否存在AHK注册表项
RegRead, FileType, %RootKey%, %Subkey%.ahk
if FileType<>
{
RegRead, value, %RootKey%, %Subkey%%FileType%\Shell\Open\Command ;AHK路径
AHK_Path:=PathGetPath(value)
RegRead, value, %RootKey%, %Subkey%%FileType%\Shell\Edit\Command ;编辑器路径
Editor_Path:=PathGetPath(value)
RegRead, value, %RootKey%, %Subkey%%FileType%\Shell\Compile\Command ;编译器路径
Compiler_Path:=PathGetPath(value)
RegRead, Template_Name, %RootKey%, %Subkey%.ahk\ShellNew, FileName ;模板文件名
}
else
FileType=AutoHotkeyScript
if AHK_Path=
{
IfExist, %A_ScriptDir%\AutoHotkey.exe
AHK_path=%A_ScriptDir%\AutoHotkey.exe
}
if Editor_Path=
{
IfExist, %A_ScriptDir%\SciTE\SciTE.exe
Editor_Path=%A_ScriptDir%\SciTE\SciTE.exe
}
if Compiler_Path=
{
IfExist, %A_ScriptDir%\Compiler\Ahk2Exe.exe
Compiler_Path=%A_ScriptDir%\Compiler\Ahk2Exe.exe
}
SplitPath, A_AhkPath,, ahkexedir
if Template_Name=
Template_Name=%ahkexedir%\Template.ahk
Gui, Add, Tab, x10 y10 w480 h250 Choose1, 设置|说明
Gui, Tab, 1
Gui, Add, GroupBox, x20 y40 w460 h50 , “运行脚本”关联的 AutoHotkey
Gui, Add, Edit, x35 y60 w340 h20 vAHK_Path, %AHK_path%
Gui, Add, Button, x385 y60 w40 h20 gFind_AHK, 浏览
Gui, Add, GroupBox, x20 y100 w460 h50 , “编辑脚本”关联的编辑器
Gui, Add, Edit, x35 y120 w340 h20 vEditor_Path, %Editor_Path%
Gui, Add, Button, x385 y120 w40 h20 gChoose_Editor, 浏览
Gui, Add, Button, x430 y120 w40 h20 gDefault_Editor, 默认
Gui, Add, GroupBox, x20 y160 w460 h50 , “编译脚本”关联的编译器
Gui, Add, Edit, x35 y180 w340 h20 vCompiler_Path, %Compiler_Path%
Gui, Add, Button, x385 y180 w40 h20 gChoose_Compiler, 浏览
Gui, Add, Button, x430 y180 w40 h20 gDefault_Compiler, 默认
Gui, Add, Checkbox, x35 y230 w270 h20 gNew_Script vNew_Script, 右键“新建”菜单中增加“AutoHotkey 脚本”
Gui, Add, Button, x310 y230 w80 h20 vEdit_Template gEdit_Template, 编辑脚本模板
Gui, Add, Button, x400 y230 w80 h20 vDelete_Template gDelete_Template, 删除脚本模板
Gui, Tab, 2
Gui, Font, bold
Gui, Add, Text,, AutoHotkey 脚本关联工具 ScriptSetting %Script_Version%
Gui, Font
Gui, Font, CBlue underline
Gui, Add, Text, gWebsite, 作者:microker(autoahk.com)、microbug(autoahk.com)`n`n中文学习论坛:https://www.autoahk.com
Gui, Font
Gui, Add, Text, w450, 此工具用来修改 AutoHotkey 脚本的右键菜单关联,适用于 AutoHotkey 安装版、绿色版。
Gui, Add, Text, w450, 您可以用它来修改默认脚本编辑器、编译器,修改默认的新建脚本模板。设置后,在右键菜单中添加“运行脚本”、“编辑脚本”、“编译脚本”和“新建 AutoHotkey 脚本”等选项。
Gui, Add, Text, w450, 要取消脚本的系统关联,请按“卸载”。注意:卸载后您将无法通过双击来运行脚本,也不能通过右键菜单来启动脚本编辑器...
Gui, Tab
if IsLimitedUser=1
Gui, Add, Button, x60 y260 w380 h20 gRunAsUACAdmin, 只为当前用户配置,如果全局配置请点击此按钮以管理员身份运行
Gui, Add, Button, x100 y285 w60 h20 Default gInstall, 配置
Gui, Add, Button, x225 y285 w60 h20 gUninstall, 卸载
Gui, Add, Button, x350 y285 w60 h20 gCancel, 关闭
Gui, Show, x250 y200 h320 w500 Center, ScriptSetting %Script_Version%
GuiControl, Disable, Edit_Template ; 使“编辑脚本模板”按钮无效
IfNotExist, %Template_Name%
GuiControl, Disable, Delete_Template ; 使“删除脚本模板”按钮无效
; 当鼠标指向链接时,指针变成手形
hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
OnMessage(0x200,"WM_MOUSEMOVE")
return
; 改变鼠标指针为手形
WM_MOUSEMOVE(wParam,lParam)
{
global hCurs
MouseGetPos,,,,ctrl
if ctrl in static2
DllCall("SetCursor","UInt",hCurs)
return
}
return
GuiClose:
GuiEscape:
Cancel:
ExitApp
; 以管理员身份运行
RunAsUACAdmin:
try
RunWait *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
return
; 查找 AutoHotkey 主程序
Find_AHK:
Gui +OwnDialogs
FileSelectFile, AHK_Path, 3, , 查找 AutoHotkey.exe, AutoHotkey.exe
if AHK_Path<>
GuiControl,,AHK_Path, %AHK_Path%
gosub Default_Compiler
return
; 选择脚本编辑器
Choose_Editor:
Gui +OwnDialogs
FileSelectFile, Editor_Path, 3, , 选择脚本编辑器, 程序(*.exe)
if Editor_Path<>
GuiControl,,Editor_Path, %Editor_Path%
return
; 默认脚本编辑器
Default_Editor:
IfExist, %A_ScriptDir%\AdventureCN\AutoAHK.exe
Editor_Path=%A_ScriptDir%\AdventureCN\AutoAHK.exe
else ifExist, %A_WinDir%\system32\notepad.exe
Editor_Path=%A_WinDir%\system32\notepad.exe
GuiControl,, Editor_Path, %Editor_Path%
return
; 选择脚本编译器
Choose_Compiler:
Gui +OwnDialogs
FileSelectFile, Compiler_Path, 3, , 选择脚本编译器, 程序(*.exe)
if Compiler_Path<>
GuiControl,,Compiler_Path, %Compiler_Path%
return
; 默认脚本编译器
Default_Compiler:
GuiControlGet, AHK_Path
SplitPath, AHK_Path, ,AHK_Dir
IfExist, %AHK_Dir%\Compiler\Ahk2Exe.exe
{
Compiler_Path=%AHK_Dir%\Compiler\Ahk2Exe.exe
GuiControl,, Compiler_Path, %Compiler_Path%
}
return
; 设置
Install:
Gui, Submit
IfNotExist, %AHK_Path%
{
MsgBox, 16, ScriptSetting %Script_Version%, AutoHotkey 路径错误 !
return
}
IfNotExist, %Editor_Path%
{
MsgBox, 16, ScriptSetting %Script_Version%, 编辑器路径错误 !
return
}
IfNotExist, %Compiler_Path%
{
MsgBox, 16, ScriptSetting %Script_Version%, 编译器路径错误 !
return
}
; 写入注册表
RegWrite, REG_SZ, %RootKey%, %Subkey%.ahk,, %FileType%
if New_Script=1
{
RegWrite, REG_SZ, %RootKey%, %Subkey%.ahk\ShellNew, FileName, %Template_Name%
IfNotExist, %Template_Name%
gosub Create_Template
}
else
{
RegDelete, %RootKey%, %Subkey%.ahk\ShellNew
IfExist, %Template_Name%
gosub Delete_Template
}
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%,, AutoHotkey 脚本
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\DefaultIcon,, %AHK_Path%`,1
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell,, Open
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Open,, 运行脚本
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Open\Command,, "%AHK_Path%" "`%1" `%*
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Runas,, 以UAC管理员身份运行脚本
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Runas, HasLUAShield,
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Runas\Command,, "%AHK_Path%" "`%1" `%*
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Edit,, 编辑脚本
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Edit\Command,, "%Editor_Path%" "`%1"
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Compile,, 编译脚本
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\Shell\Compile-Gui, , 编译脚本 (对话框)...
IfInString, Compiler_Path, Ahk2Exe.exe
{
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Compile\Command,, "%Compiler_Path%" /in "`%1"
RegWrite, REG_SZ, %RegRoot%\AutoHotkeyScript\Shell\Compile-Gui\Command, , "%Compiler_Path%" /gui /in "`%l" `%*
}
else
{
RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Compile\Command,, "%Compiler_Path%" "`%1"
}
MsgBox, 64, ScriptSetting %Script_Version%, 设置完毕 !
ExitApp
; 卸载
Uninstall:
MsgBox, 36, ScriptSetting %Script_Version%
, 注意:卸载后您将无法通过双击来运行脚本,也不能通过右键菜单来启动脚本编辑器...`n`n确定要取消 AHK 脚本的系统关联吗 ?
IfMsgBox, Yes
{
RegDelete, %RootKey%, %Subkey%.ahk
RegDelete, %RootKey%, %Subkey%%FileType%
gosub Delete_Template
if IsLimitedUser=0
{
RegRead, FileType, HKCU, Software\Classes\.ahk
if FileType<>
RegDelete, HKCU, Software\Classes\.ahk
RegRead, FileType, HKCU, Software\Classes\%FileType%
if FileType<>
RegDelete, HKCU, Software\Classes\%FileType%
}
ExitApp
}
return
; 编辑脚本模板
Edit_Template:
GuiControlGet, Editor_Path
IfNotExist, %Editor_Path%
{
MsgBox, 64, ScriptSetting %Script_Version%, 脚本编辑器路径错误 !
return
}
IfNotExist, %Template_Name%
gosub Create_Template
Run, %Editor_Path% %Template_Name%
return
; 使编辑脚本模板按钮有效/无效
New_Script:
GuiControlGet, New_Script
if New_Script=0
GuiControl, Disable, Edit_Template
else
GuiControl, Enable, Edit_Template
return
; 新建脚本模板
Create_Template:
GuiControlGet, AHK_Path
FileGetVersion, AHK_Ver, %AHK_Path%
FileAppend,
(
/*
AutoHotkey 版本: %A_AhkVersion%
操作系统: %A_OSVersion%
作者: %A_UserName%
脚本说明:
脚本版本: v1.0
*/
#NoEnv
FileEncoding UTF-16
SendMode Input
SetWorkingDir `%A_ScriptDir`%
), %Template_Name%, UTF-16
GuiControl, Enable, Delete_Template ; 使“删除脚本模板”按钮有效
return
; 删除脚本模板
Delete_Template:
MsgBox, 36, ScriptSetting %Script_Version%
, 要删除当前的 AHK 脚本模板吗 ?`n`n脚本模板被删除后,仍可通过本工具重建模板。
IfMsgBox, Yes
FileDelete, %Template_Name%
GuiControl, Disable, Delete_Template ; 使“删除脚本模板”按钮无效
return
; 打开网站
Website:
Run, https://www.autoahk.com
return
; 从注册表值字符串中提取路径
PathGetPath(pSourceCmd)
{
local Path, ArgsStartPos = 0
if (SubStr(pSourceCmd, 1, 1) = """")
Path := SubStr(pSourceCmd, 2, InStr(pSourceCmd, """", False, 2) - 2)
else
{
ArgsStartPos := InStr(pSourceCmd, " ")
if ArgsStartPos
Path := SubStr(pSourceCmd, 1, ArgsStartPos - 1)
else
Path = %pSourceCmd%
}
return Path
}
博主,V2版本的在哪?谢谢!
冒泡
一天只能下载一次吗
普通用户是的
ASD
新人打卡
新人报到
?
新人报道
大佬流弊,感谢
不错不错~谢谢大佬?
xx
谢谢分享
谢谢分享
谢谢分享帮助文档
大佬流弊,感谢
好用的工具
谢谢分享帮助文档