delphixx

一键安装AutoHotkey自动化热键脚本语言编程环境 By BoAi

595076941@QQ.com

2019年02月21日

 

 1 rem 一键安装AutoHotkey自动化热键脚本语言编程环境
 2 
 3 D:
 4 cd \Program\AutoHotkey
 5 
 6 rem 设置ahk文件类型关联到AutoHotkeyU32.exe
 7 rem 以便运行脚本
 8 rem 解压缩“AutoHotkey_1.1.30.01_setup.exe”安装文件得到setup.exe
 9 
10 rem 由于AutoHotkey的安装包会记住上次安装的位置,
11 rem 为了软件安装位置固定到D:\Program文件夹所以此处必需指定安装目标文件夹
12 D:\Program\AutoHotkey\ahksetup.exe  /S /D=D:\Program\AutoHotkey
13 
14 rem 添加ahk文件类型鼠标右键菜单
15 rem 运行、编辑、编译脚本的关联,感谢甲壳虫和兔子写出这么好的脚本
16 D:\Program\AutoHotkey\autohotkeyu32.exe D:\Program\AutoHotkey\MenuSetup.ahk
View Code (AHKSetup.BAT)

 

  1 /*
  2 AutoHotkey 版本: 1.x
  3 操作系统:    WinXP
  4 作者:        甲壳虫<jdchenjian@gmail.com>
  5 博客:        http://hi.baidu.com/jdchenjian
  6 脚本说明:   此工具用来修改 AutoHotkey 脚本的右键菜单关联,适用于 AutoHotkey 安装版、绿色版。
  7 脚本版本:   2009-01-21
  8 
  9 修改作者:    兔子
 10 更新说明:
 11 2010.01.09    之前某个时间,修改AHK路径、编辑器路径、编译器路径,默认全部在当前目录下寻找
 12 2010.01.09    去掉默认在新建菜单的勾
 13 2010.06.21    如果SCITE为默认编辑器,则复制个人配置文件“SciTEUser.properties”到%USERPROFILE%
 14 2010.06.25    修正因#NoEnv使%USERPROFILE%变量直接引用无效
 15 2016.04.18    删除“2010.06.21”的改动
 16 */
 17 
 18 ; --- 20190207 晓亮修改 ---
 19 
 20 #NoEnv
 21 #SingleInstance, force
 22 SendMode Input
 23 SetWorkingDir %A_ScriptDir%
 24 
 25 ; 版本(仅用于显示)
 26 Script_Version=v1.0.3.2
 27 
 28 ; AutoHotkey 原版的相关信息写在注册表HKCR主键中,
 29 ; 尝试是当前用户否有权操作该键,如果无权操作HKCR键(受限用户),
 30 ; 可通过操作注册表HKCU键来实现仅当前用户关联AHK脚本。
 31 IsLimitedUser:=0
 32 RegWrite, REG_SZ, HKCR, .test
 33 if ErrorLevel
 34     IsLimitedUser:=1
 35 RegDelete, HKCR, .test
 36 if ErrorLevel
 37     IsLimitedUser:=1
 38 
 39 if IsLimitedUser=0 ; 非受限用户操作HKCR键
 40 {
 41     RootKey=HKCR
 42     Subkey=
 43 }
 44 else ; 受限用户操作HKCU键
 45 {
 46     RootKey=HKCU
 47     Subkey=Software\Classes\ ; <-- 为简化后面的脚本,此子键须以“\”结尾
 48 }
 49 
 50 ; 检查是否存在AHK注册表项
 51 RegRead, FileType, %RootKey%, %Subkey%.ahk
 52 if FileType<>
 53 {
 54     RegRead, value, %RootKey%, %Subkey%%FileType%\Shell\Open\Command ;AHK路径
 55     AHK_Path:=PathGetPath(value)
 56     RegRead, value, %RootKey%, %Subkey%%FileType%\Shell\Edit\Command ;编辑器路径
 57     Editor_Path:=PathGetPath(value)
 58     RegRead, value, %RootKey%, %Subkey%%FileType%\Shell\Compile\Command ;编译器路径
 59     Compiler_Path:=PathGetPath(value)
 60     RegRead, Template_Name, %RootKey%, %Subkey%.ahk\ShellNew, FileName ;模板文件名
 61 }
 62 else
 63     FileType=AutoHotkeyScript
 64 
 65 if AHK_Path=
 66 {
 67     IfExist, %A_ScriptDir%\AutoHotkey.exe
 68         AHK_path=%A_ScriptDir%\AutoHotkey.exe
 69 }
 70 
 71 if Editor_Path=
 72 {
 73     IfExist, %A_ScriptDir%\SciTE\SciTE.exe
 74         Editor_Path=%A_ScriptDir%\SciTE\SciTE.exe
 75 }
 76 
 77 if Compiler_Path=
 78 {
 79     IfExist, %A_ScriptDir%\Compiler\Ahk2Exe.exe
 80         Compiler_Path=%A_ScriptDir%\Compiler\Ahk2Exe.exe
 81 }
 82 
 83 if Template_Name=
 84     Template_Name=Template.ahk
 85 
 86 ; --- 20190207 晓亮修改 ---
 87 ;设置AHK默认文件夹为D:\Program\AutoHotkey
 88 AHK_path=D:\Program\AutoHotkey\AutoHotkeyU32.exe
 89 Editor_Path=D:\Program\AutoHotkey\SciTE\SciTE.exe
 90 Compiler_Path=D:\Program\AutoHotkey\Compiler\Ahk2Exe.exe
 91 
 92 Gui, Add, Tab, x10 y10 w480 h250 Choose1, 设置|说明
 93     Gui, Tab, 1
 94         Gui, Add, GroupBox, x20 y40 w460 h50 , “运行脚本”关联的 AutoHotkey
 95         Gui, Add, Edit, x35 y60 w340 h20 vAHK_Path, %AHK_path%
 96         Gui, Add, Button, x385 y60 w40 h20 gFind_AHK, 浏览
 97 
 98         Gui, Add, GroupBox, x20 y100 w460 h50 , “编辑脚本”关联的编辑器
 99         Gui, Add, Edit, x35 y120 w340 h20 vEditor_Path, %Editor_Path%
100         Gui, Add, Button, x385 y120 w40 h20 gChoose_Editor, 浏览
101         Gui, Add, Button, x430 y120 w40 h20 gDefault_Editor, 默认
102 
103         Gui, Add, GroupBox, x20 y160 w460 h50 , “编译脚本”关联的编译器
104         Gui, Add, Edit, x35 y180 w340 h20 vCompiler_Path, %Compiler_Path%
105         Gui, Add, Button, x385 y180 w40 h20 gChoose_Compiler, 浏览
106         Gui, Add, Button, x430 y180 w40 h20 gDefault_Compiler, 默认
107 
108         Gui, Add, Checkbox, x35 y230 w270 h20 gNew_Script vNew_Script, 右键“新建”菜单中增加“AutoHotkey 脚本”
109         Gui, Add, Button, x310 y230 w80 h20 vEdit_Template gEdit_Template, 编辑脚本模板
110         Gui, Add, Button, x400 y230 w80 h20 vDelete_Template gDelete_Template, 删除脚本模板
111 
112     Gui, Tab, 2
113         Gui, Font, bold
114         Gui, Add, Text,, AutoHotkey 脚本关联工具  ScriptSetting %Script_Version%
115         Gui, Font
116         Gui, Font, CBlue underline
117         Gui, Add, Text, gWebsite, 作者:甲壳虫 <jdchenjian@gmail.com>`n`n博客:http://hi.baidu.com/jdchenjian
118         Gui, Font
119         Gui, Add, Text, w450, 此工具用来修改 AutoHotkey 脚本的右键菜单关联,适用于 AutoHotkey 安装版、绿色版。
120         Gui, Add, Text, w450, 您可以用它来修改默认脚本编辑器、编译器,修改默认的新建脚本模板。设置后,在右键菜单中添加“运行脚本”、“编辑脚本”、“编译脚本”和“新建 AutoHotkey 脚本”等选项。
121         Gui, Add, Text, w450, 要取消脚本的系统关联,请按“卸载”。注意:卸载后您将无法通过双击来运行脚本,也不能通过右键菜单来启动脚本编辑器...
122 
123 Gui, Tab
124 Gui, Add, Button, x100 y270 w60 h20 Default gInstall, 设置
125 Gui, Add, Button, x200 y270 w60 h20 gUninstall, 卸载
126 Gui, Add, Button, x300 y270 w60 h20 gCancel, 取消
127 
128 Gui, Show, x250 y200 h300 w500 CEnter, ScriptSetting %Script_Version%
129 GuiControl, Disable, Edit_Template ; 使“编辑脚本模板”按钮无效
130 IfNotExist, %A_WinDir%\ShellNew\%Template_Name%
131     GuiControl, Disable, Delete_Template ; 使“删除脚本模板”按钮无效
132 
133 ; 当鼠标指向链接时,指针变成手形
134 hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
135 OnMessage(0x200,"WM_MOUSEMOVE")
136 
137 ; --- 20190207 晓亮修改 ---
138 goto,Install
139 return
140 
141 ; 改变鼠标指针为手形
142 WM_MOUSEMOVE(wParam,lParam)
143 {
144     global hCurs
145     MouseGetPos,,,,ctrl
146     if ctrl in static2
147         DllCall("SetCursor","UInt",hCurs)
148     return
149 }
150 return
151 
152 GuiClose:
153 GuiEscape:
154 Cancel:
155     ExitApp
156 
157     ; 查找 AutoHotkey 主程序
158 Find_AHK:
159     Gui +OwnDialogs
160     FileSelectFile, AHK_Path, 3, , 查找 AutoHotkey.exe, AutoHotkey.exe
161     if AHK_Path<>
162         GuiControl,,AHK_Path, %AHK_Path%
163     gosub Default_Compiler
164 return
165 
166 ; 选择脚本编辑器
167 Choose_Editor:
168     Gui +OwnDialogs
169     FileSelectFile, Editor_Path, 3, , 选择脚本编辑器, 程序(*.exe)
170     if Editor_Path<>
171         GuiControl,,Editor_Path, %Editor_Path%
172 return
173 
174 ; 默认脚本编辑器
175 Default_Editor:
176     IfExist, %A_ScriptDir%\SciTE\SciTE.exe
177         Editor_Path=%A_ScriptDir%\SciTE\SciTE.exe
178     else ifExist, %A_WinDir%\system32\notepad.exe
179             Editor_Path=%A_WinDir%\system32\notepad.exe
180     GuiControl,, Editor_Path, %Editor_Path%
181 return
182 
183 ; 选择脚本编译器
184 Choose_Compiler:
185     Gui +OwnDialogs
186     FileSelectFile, Compiler_Path, 3, , 选择脚本编译器, 程序(*.exe)
187     if Compiler_Path<>
188         GuiControl,,Compiler_Path, %Compiler_Path%
189 return
190 
191 ; 默认脚本编译器
192 Default_Compiler:
193     GuiControlGet, AHK_Path
194     SplitPath, AHK_Path, ,AHK_Dir
195     IfExist, %AHK_Dir%\Compiler\Ahk2Exe.exe
196     {
197         Compiler_Path=%AHK_Dir%\Compiler\Ahk2Exe.exe
198         GuiControl,, Compiler_Path, %Compiler_Path%
199     }
200 return
201 
202 ; 设置
203 Install:
204     Gui, Submit
205     IfNotExist, %AHK_Path%
206     {
207         MsgBox, 16, ScriptSetting %Script_Version%, AutoHotkey 路径错误 !
208         return
209     }
210 
211     IfNotExist, %Editor_Path%
212     {
213         MsgBox, 16, ScriptSetting %Script_Version%, 编辑器路径错误 !
214         return
215     }
216 
217     IfNotExist, %Compiler_Path%
218     {
219         MsgBox, 16, ScriptSetting %Script_Version%, 编译器路径错误 !
220         return
221     }
222 
223     ; 写入注册表
224     RegWrite, REG_SZ, %RootKey%, %Subkey%.ahk,, %FileType%
225     if New_Script=1
226     {
227         RegWrite, REG_SZ, %RootKey%, %Subkey%.ahk\ShellNew, FileName, %Template_Name%
228         IfNotExist, %A_WinDir%\ShellNew\%Template_Name%
229             gosub Create_Template
230     }
231     else
232     {
233         ; --- 20190207 晓亮修改 ---
234         ; --- 此处不要删除右键新建ahk文件的菜单所以注释掉此代码
235         ;RegDelete, %RootKey%, %Subkey%.ahk\ShellNew
236         IfExist, %A_WinDir%\ShellNew\%Template_Name%
237             gosub Delete_Template
238     }
239 
240     RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%,, AutoHotkey 脚本
241     RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\DefaultIcon,, %AHK_Path%`,1
242     RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell,, Open
243     RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Open,, 运行脚本
244     RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Open\Command,, "%AHK_Path%" "`%1" `%*
245     RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Edit,, 编辑脚本
246     RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Edit\Command,, "%Editor_Path%" "`%1"
247     RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Compile,, 编译脚本
248     IfInString, Compiler_Path, Ahk2Exe.exe
249         RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Compile\Command,, "%Compiler_Path%" /in "`%1"
250     else
251         RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%\Shell\Compile\Command,, "%Compiler_Path%" "`%1"
252 
253 /*        新版的scite不需要将“SciTEUser.properties”放在“USERPROFILE”目录下了
254 if Editor_Path=%A_ScriptDir%\SciTE\SciTE.exe
255 {
256 EnvGet,USERPROFILE,USERPROFILE
257 FileCopy,%A_ScriptDir%\SciTE\SciTEUser.properties,%USERPROFILE%\SciTEUser.properties,1
258 }
259 */
260 
261     ;MsgBox, 64, ScriptSetting %Script_Version%, 设置完毕 !
262     ExitApp
263 
264     ; 卸载
265 Uninstall:
266     ; --- 20190207 晓亮修改 ---
267     ;MsgBox, 36, ScriptSetting %Script_Version%
268     ;, 注意:卸载后您将无法通过双击来运行脚本,也不能通过右键菜单来启动脚本编辑器...`n`n确定要取消 AHK 脚本的系统关联吗 ?
269     ;IfMsgBox, Yes
270     ;{
271     ;RegDelete, %RootKey%, %Subkey%.ahk
272     ;RegDelete, %RootKey%, %Subkey%%FileType%
273     ;gosub Delete_Template
274     ;ExitApp
275     ;}
276 return
277 
278 ; 编辑脚本模板
279 Edit_Template:
280     GuiControlGet, Editor_Path
281     IfNotExist, %Editor_Path%
282     {
283         MsgBox, 64, ScriptSetting %Script_Version%, 脚本编辑器路径错误 !
284         return
285     }
286     IfNotExist, %A_WinDir%\ShellNew\%Template_Name%
287         gosub Create_Template
288     Run, %Editor_Path% %A_WinDir%\ShellNew\%Template_Name%
289 return
290 
291 ; 使编辑脚本模板按钮有效/无效
292 New_Script:
293     GuiControlGet, New_Script
294     if New_Script=0
295         GuiControl, Disable, Edit_Template
296     else
297         GuiControl, Enable, Edit_Template
298 return
299 
300 ; 新建脚本模板
301 Create_Template:
302     GuiControlGet, AHK_Path
303     FileGetVersion, AHK_Ver, %AHK_Path%
304 
305     FileAppend,
306     (
307 /*
308 AutoHotkey 版本: %AHK_Ver%
309 操作系统:    %A_OSVersion%
310 作者:        %A_UserName%
311 网站:        http://www.AutoHotkey.com
312 脚本说明:
313 脚本版本:   v1.0
314 */
315 
316 #NoEnv
317 SendMode Input
318 SetWorkingDir `%A_ScriptDir`%
319 
320     ), %A_WinDir%\ShellNew\%Template_Name%
321 
322     GuiControl, Enable, Delete_Template ; 使“删除脚本模板”按钮有效
323 return
324 
325 ; 删除脚本模板
326 Delete_Template:
327 
328     ; --- 20190207 晓亮修改 ---
329     ;MsgBox, 36, ScriptSetting %Script_Version%
330     ;    , 要删除当前的 AHK 脚本模板吗 ?`n`n脚本模板被删除后,仍可通过本工具重建模板。
331     ;IfMsgBox, Yes
332     ;FileDelete, %A_WinDir%\ShellNew\%Template_Name%
333     ;GuiControl, Disable, Delete_Template ; 使“删除脚本模板”按钮无效
334 return
335 
336 ; 打开网站
337 Website:
338     Run, http://hi.baidu.com/jdchenjian
339 return
340 
341 ; 从注册表值字符串中提取路径
342 PathGetPath(pSourceCmd)
343 {
344     local Path, ArgsStartPos = 0
345     if (SubStr(pSourceCmd, 1, 1) = """")
346         Path := SubStr(pSourceCmd, 2, InStr(pSourceCmd, """", False, 2) - 2)
347     else
348     {
349         ArgsStartPos := InStr(pSourceCmd, " ")
350         if ArgsStartPos
351             Path := SubStr(pSourceCmd, 1, ArgsStartPos - 1)
352         else
353             Path = %pSourceCmd%
354     }
355     return Path
356 }
View Code (MenuSetup.AHK)

 

Easy7z.exe

 

 1 [BasicSet]
 2 7zFile=D:\Personal\Desktop\1K_AHKSetup.7z
 3 ExeFile=D:\Personal\Desktop\1K_AHKSetup.exe
 4 IconFile=D:\Personal\Desktop\Project1_Icon.ico
 5 IconIndex=-1
 6 InstallPath=D:\Program\
 7 OverwriteMode0=4
 8 OverwriteMode1=1
 9 OverwriteMode2=4
10 SelfDelete1=4
11 SelfDelete0=1
12 [GuiSetMain]
13 Title= 一键安装AutoHotkey 2019年2月20日 595076941@QQ.com
14 LogoFile=(默认)
15 IconShow=1
16 [GuiSetBegin]
17 Begin=4
18 BeginPrompt=
19 BeginMode1=1
20 BeginMode2=4
21 BeginMode3=4
22 [GuiSetPath]
23 Path=4
24 ExtractPathTitle=
25 ExtractPathText=
26 PathMode1=1
27 PathMode2=4
28 PathMode3=4
29 [GuiSetProgress]
30 Progress=1
31 ExtractTitle=一键安装AutoHotkey 2019年2月20日 595076941@QQ.com
32 ExtractDialogText= 一键安装AutoHotkey 2019年2月20日 595076941@QQ.com 徐晓亮
33 ProgressMode1=4
34 ProgressMode2=1
35 ProgressMode3=4
36 [GuiSetFinish]
37 Finish=4
38 FinishMessage=
39 FinishMode1=1
40 FinishMode2=4
41 FinishMode3=4
42 [GuiSetHelp]
43 Help=4
44 HelpText=
45 HelpMode1=1
46 HelpMode2=4
47 HelpMode3=4
48 [AdvancedSet]
49 RunProgram=AutoHotkey\Setup.bat||4|4|0|0|0|0
View Code (E7zSet_20190220.e7z)

 

相关文章: