例子:到达指定时间自动执行所需操作

优质
小牛编辑
117浏览
2023-12-01

引用AutoRun.nsi的内容:

; AutoRun.nsi
; 到达指定时间自动执行所需操作的脚本例子
; 编写:zhfi 
; 注意:必须使用附带的修改版InstallOption或者是新版的InstallOptionEx插件方可实现!

;--------------------------------
;添加插件目录
!AddPluginDir .\

!include LogicLib.nsh

;定义INI文件
!define INI $PLUGINSDIR\Auto.ini
;定义自定义页面句柄存放变量
var hwnd

Name AutoRun
OutFile AutoRun.exe

;--------------------------------

;自定义页面
Page custom SetCustom LeaveCustom

Section Nil
SectionEnd

Function .onInit
;创建临时插件目录并释放INI文件
  InitPluginsDir
  File /oname=${INI} "Auto.ini"
FunctionEnd

Function .onGUIEnd
;释放插件
        Delay::Free
FunctionEnd

Function SetCustom
    Var /GLOBAL PageDone
    IntCmp $PageDone 1 free
    InstallOptions::initDialog /NOUNLOAD ${INI}
    Pop $hwnd
    GetDlgItem $0 $hwnd 1201
    ;此处的倒计时时间(5秒)必须与ini中定义一致!
    Delay::DelayButton /NOUNLOAD $0 5 ""
    StrCpy $PageDone 1
    InstallOptions::Show
    Goto end
    free:
    Delay::Free
    end:

FunctionEnd

Function LeaveCustom
;这个函数中存放你要执行的操作代码
  MessageBox MB_OK '完成!'
FunctionEnd

引用Auto.ini的内容:

;By zhfi 
;NumFields必须不能为0
;TimeOut表示自动退出的执行时间(单位:毫秒)
[Settings]
NumFields=3
TimeOut=5000
Title="在指定时间执行预定操作的脚本例子"

[Field 1]
Type=Label
Text=离自动XX还有:
Left=30
Right=90
Top=10
Bottom=25

[Field 2]
Type=Label
Text=XX
Left=95
Right=105
Top=10
Bottom=25

[Field 3]
Type=Label
Text=秒
Left=115
Right=130
Top=10
Bottom=30