学习了AutoIT 两三日,写了几个自动安装软件的脚本,发一个出来,请大家指点一下。
其中对CheckListBox控件的控制还是参考的论坛里的高手写的,在这里谢谢他们了。
自动安装RealVNC 4.1.3(英文版)
;一键安装RealVNC 4.1.3
Opt("TrayIconDebug", 1) ;0=无信息, 1=调试信息
Opt("WinTextMatchMode", 2) ;1=完全匹配, 2=快速匹配
Opt("WinTitleMatchMode", 4) ;1=开头, 2=子串, 3=完全, 4=高级
Opt("WinSearchChildren", 1) ;0=不搜索, 1=搜索子窗口
Opt("WinDetectHiddenText", 1) ;0=不检测, 1=检测
Dim $Exe,$SMessage01,$STitle01,$STitle02,$SText02,$STitle03
$Exe='c:\vnc-4_1_3-x86_win32.exe'
$SMessage01=$Exe &'不存在,退出安装!'
$STitle01='一键安装RealVNC 4.1.3'
$STitle02='打开文件 - 安全警告'
$SText02='运行(&R)'
$STitle03='Setup - VNC'
If Not FileExists($Exe) Then ;判断安装文件是否在指定路径
MsgBox(4096,$STitle01,$SMessage01)
Exit
EndIf
Run($Exe)
Do ;判断是否出现打开文件的安全警告
If WinExists($STitle02) Then
WinWaitActive($STitle02)
ControlClick($STitle02,$SText02,"Button1")
EndIf
Until WinExists($STitle03)
WinWaitActive($STitle03)
ControlClick($STitle03,"&Next >","TNewButton1")
WinWaitActive($STitle03) ;许可协议
ControlClick($STitle03,"Click Next to continue, or Cancel to exit Setup","TNewRadioButton1")
ControlClick($STitle03,"Click Next to continue, or Cancel to exit Setup","TNewButton2")
WinWaitActive($STitle03) ;安装路径
ControlClick($STitle03,"&Next >","TNewButton3")
WinWaitActive($STitle03) ;选择安装Server和View
ControlClick($STitle03,"&Next >","TNewButton3")
WinWaitActive($STitle03) ;设置开始菜单
ControlClick($STitle03,"&Next >","TNewButton4")
WinWaitActive($STitle03) ;需要去掉开机运行VNC服务的选项的勾
Dim $IWinPosArray,$ICheckListBoxArray,$Iwidth,$IHeight
$IWinPosArray=WinGetPos($STitle03) ;获得窗口的坐标
$ICheckListBoxArray=ControlGetPos($STitle03,"&Next >","TNewCheckListBox1") ;获得控件在该窗口的坐标
$Iwidth=$IWinPosArray[0]+$ICheckListBoxArray[0] ;获得控件相对于系统的坐标
$IHeight=$IWinPosArray[1]+$ICheckListBoxArray[1]
If PixelGetColor($Iwidth+10,$IHeight+10)<>0 Then ;判断有无打勾
MouseClick("left",$Iwidth+10,$IHeight+120) ;取消Register and configure VNC Server for Service-Mode的勾
EndIf
If PixelGetColor($Iwidth+10,$IHeight+10) <> 0 Then ;判断有无打勾
MouseClick("left",$Iwidth+10,$IHeight+142) ;取消Start the VNC Server in Service-Mode的勾
EndIf
ControlClick($STitle03,"&Next >","TNewButton4")
WinWaitActive($STitle03) ;开始安装
ControlClick($STitle03,"&Install","TNewButton4")
;MsgBox(4096,"","001")
WinWaitActive($STitle03,"Information")
ControlClick($STitle03,"Information","TNewButton4")
WinWaitActive($STitle03)
ControlClick($STitle03,"&Finish","TNewButton4")
MsgBox(0,$STitle01,"恭喜,成功安装完成!",3) |