四、下面我们以MathType 5.2c的安装为例子,简单介绍脚本的制作。
1、双击安装文件,然后会弹出如下安装选项
通过Autoit Window Spy工具获得窗体详细信息,具体操作:
在开始菜单里依次选择“程序—AutoIt V3—Autoit Window Spy”。“Autoit Window Spy”启动后一般它都在最上面,鼠标激活要查看信息的窗体,“Autoit Window Spy”窗体里将显示激活窗体在鼠标下的信息,如图,这时可以用Ctrl+Alt+F使窗口内容暂停,便于从窗体里复制需要的内容。
可以看到窗体的标题为:“MathType 5.2c - InstallShield Wizard”,可见窗体文本我们可以取:“License Gran ”
小写字母a下有横线,可以用alt+a代替鼠标操作。选择后,灰色按钮激活,按回车即可。
这一步的命令为:
run("MathType52Setup.exe")
WinWaitActive("MathType 5.2c - InstallShield Wizard","License Grant")
Send("!a")
send("{enter}")
2、继续,到了这一步,要填写注册信息
从图中,我们可以看到鼠标所在的控件名称为“edit1”,内容为“user”,可以通过ControlSend命令实现自动填写,同理可以填写其他注册信息,然后回车即可进入下一步。
这一步的完整命令为:
WinWaitActive("MathType 5.2c Setup","&Unlock MathType")
ControlSend("MathType 5.2c Setup","","Edit1","user")
ControlSend("MathType 5.2c Setup","","Edit2","user")
ControlSend("MathType 5.2c Setup","","Edit3","user")
ControlSend("MathType 5.2c Setup","","Edit4","MTWE521-011740-7sdwr")
send("{enter}")
3、如果不想改动,直接下一步。
问:如何改默认路径?
答:详见(下)篇:修改默认路径(ControlSetText和ControlSend)
这里我们为了方便,直接按照默认(在实际安装中,我们会发现,如果存在同名空文件夹,安装将会中断,在后面我们会详细讨论这个问题),回车即可。截图里的信息表明,我们还可以用ControlClick实现模拟鼠标点击,在此不在赘述。
这一步的命令为:
WinWaitActive("MathType 5.2c Setup","Click OK to install MathType")
Send("{enter}")
4.单击ok即可。
这一步的命令为:
WinWaitActive("Installation Complete","")
ControlClick("Installation Complete","",1)
完整的脚本:
Opt("WinWaitDelay",100)
BlockInput(1)
If FileExists(@ProgramFilesDir&"\MathType\MathType.exe") Then;;;判断程序是否安装过,如果安装则退出!
MsgBox ( 4096, "安装提示", "你已经安装了Mathtype", 2 );;;信息窗口
Exit
EndIf
run("MathType52Setup.exe")
WinWaitActive("MathType 5.2c - InstallShield Wizard","License Grant")
Send("!a")
send("{enter}")
WinWaitActive("MathType 5.2c Setup","&Unlock MathType")
ControlSend("MathType 5.2c Setup","","Edit1","user")
ControlSend("MathType 5.2c Setup","","Edit2","user")
ControlSend("MathType 5.2c Setup","","Edit3","user")
ControlSend("MathType 5.2c Setup","","Edit4","MTWE521-011740-7sdwr")
send("{enter}")
WinWaitActive("MathType 5.2c Setup","Click OK to install MathType")
Send("{enter}")
If WinWaitActive("MathType 5.2c Setup","MathType does not exist") Then
send("!y")
EndIf
ControlClick("MathType 5.2c Setup","是(&Y)","Button1")
send("!Y")
WinWaitActive("Installation Complete","")
ControlClick("Installation Complete","",1)
BlockInput(0)