一个替换编译后资源文件的参考示例
#NoEnv
SetBatchLines -1
SetWorkingDir %A_ScriptDir%
FileSelectFile, AHK解释器路径, , %A_ScriptDir%,选择要替换脚本内容的编译,*.exe
if (AHK解释器路径="")
ExitApp
; AHK解释器路径 := A_ScriptFullPath ; 解掉这行就是替换自身代码并更新运行
FileCopy, %AHK解释器路径%, %A_ScriptDir%\替换原脚本内容.exe, 1 ; 覆盖
if ErrorLevel
Return
根目录路径生成exe := A_ScriptDir "\替换原脚本内容.exe"
; FileRead, hModule, *c %根目录路径生成exe%
hModule := DllCall("LoadLibraryEx", "Str", 根目录路径生成exe, "Ptr", 0, "Int", 0x02, "Ptr") ; 一旦不需要,用FreeLibrary函数释放DLL
file := A_ScriptDir "\新脚本内容.ahk"
if !FileExist(file) {
MsgBox 新脚本内容 不存在
ExitApp
}
FileGetSize, filesize, %file%
; VarSetCapacity(filedata, filesize)
FileRead, filedata, *c %file%
; fxx := FileOpen(file, "r", "UTF-8-RAW")
; fxx.RawWrite(filedata, filesize)
; fxx := ""
; MsgBox % filesize
hUpdate := DllCall("BeginUpdateResource", "str", 根目录路径生成exe, "uint", 0, "ptr")
; 对指定名称路径,写入资源文件【比如脚本内容】
DllCall("UpdateResource", "ptr", hUpdate, "ptr", 10, "str", ">AUTOHOTKEY SCRIPT<", "ushort", 0x409, "ptr", &filedata, "uint", filesize, "uint")
; 清除指定名称资源文件
; DllCall("UpdateResource", "ptr", hUpdate, "ptr", 10, "str", ">AUTOHOTKEY SCRIPT<", "ushort", 0x409, "Ptr",0, "Int",0, "uint")
; MsgBox % &hUpdate
DllCall("EndUpdateResource", "ptr", hUpdate, "uint", 0) ; 保存到文件
; module := DllCall("BeginUpdateResource", "str", ExeFile, "uint", 0, "ptr")
; https://baike.baidu.com/item/EndUpdateResource/6374883?fr=aladdin
Run % 根目录路径生成exe
; BinRun(&hModule)
; Sleep 10000
Return
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。

评论(0)