; Include this code at the beginning of a script to provide self-compiling functionality. ; When the .ahk file is run it will prompt to compile, but the .exe will run as intended. ; ; You can set the following compile parameter variables: ; OUT optional folder path (create exe with same name as script in that folder), ; or full path including a different exe name if required. ; ICON optional path & name of an icon file, default is AutoHotkey icon. ; PASS optional password to encrypt the script within the exe. ; ; Example: ; OUT=D:\Temp\ ; ICON=C:\Windows\System\Icons\Setup.ico ; PASS=encrypt ; #include,!compile.ahk ; IfInString,A_ScriptName,.ahk { StringTrimRight,name,A_ScriptName,4 RegRead,cmd,HKEY_CLASSES_ROOT,AutoHotkeyScript\Shell\Compile\Command StringTrimRight,cmd,cmd,4 IfEqual,out,,StringReplace,out,A_ScriptFullPath,.ahk,.exe ; default to same folder & name IfNotInString,out,.exe,SetEnv,out,%out%\%name%.exe ; same name in specified folder StringReplace,out,out,\\,\,All SetEnv,cmd,%cmd% "%A_ScriptFullPath%" /out "%out%" SetEnv,msg,Input`t`t%A_ScriptFullPath%`nOutput`t`t%out% If icon> { SetEnv,cmd,%cmd% /icon "%icon%" SetEnv,msg,%msg%`nIcon`t`t%icon% } If pass> { SetEnv,cmd,%cmd% /pass "%pass%" SetEnv,msg,%msg%`nPassword`t`t%pass% } MsgBox,1,Compile this script?,%msg% IfMsgBox,ok,Run,%cmd% Exit }
Create self-compiling scripts
Started by
MikeG
, May 18 2004 03:50 AM
2 replies to this topic
Here's some code I have been using to make scripts "self-compiling". This makes things much easier for testing when you might want to re-compile many times. You just double click the .ahk file and you're prompted to confirm the compilation with the options shown. #include it in your scripts, as shown in the example comments.
#1
-
Posted 18 May 2004 - 03:50 AM
Self-compiling scripts, great idea. I like how you discovered that A_ScriptName contains .exe vs. .ahk if the script is compiled. I had forgotten that this is a great way for a script to detect if it is running in compiled form or not.
#2
-
Posted 18 May 2004 - 11:49 AM
very nice idea. thanx for sharing!
#3
-
Posted 18 May 2004 - 05:57 PM
CleanNews.in : Bite sized latest news headlines from India with zero bloat