AutoIt3 自动化工具

来源:互联网 发布:如何做淘宝详情页 编辑:程序博客网 时间:2024/06/07 09:18

AutoIt3 实现自动化安装

Au3脚本是AutoIt3 Windows自动安装脚本语言,AutoIt 是一种自动控制工具。它可以被用来自动完成任何基于 Windows 或 DOS 的简单任务。它最初被设计用来自动完成安装那些其它方法不能自动安装的软件。

(1).AutoIt3 设置系统环境变量

代码块

Func setEnv($logFileName)     $path=RegRead($regenv, "path")    if stringinstr($path,"System32")==0 then    _FileWriteLog($logFileName,"正在添加系统的环境变量……")    $path = $path & ";C:\Windows\System32"    RegWrite($regenv,"path","REG_EXPAND_SZ",$path)     MsgBox(4096, "Path variable should be %USERPROFILE%\Local Settings\TempChange:", "环境变量设置成功:"&RegRead($regenv, "path"))    _FileWriteLog($logFileName,"添加系统的环境变量成功……")    EnvUpdate()    Else    _FileWriteLog($logFileName,"系统不需要添加环境变量……")    endif    $path=RegRead($regenv, "path")EndFunc 

(2).AutoIt3 设置IE

代码块

    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2","1609","reg_dword" ,"0x00000000")    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TabbedBrowsing","PopupsUseNewWindow","REG_DWORD","2")    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\CommandBar","ShowCompatibilityViewButton","REG_DWORD","1")    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2","Flags","reg_dword","0x00000043")    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\134.128.*.*","http","REG_DWORD","2")

(3).AutoIt3 自动安装插件

自动安装代码块

Func installIE($logFileName)    $file_e=@ScriptDir & "\tools\" & "高拍仪控件下载.exe"    $e="WinRAR 自解压文件"    _FileWriteLog($logFileName,"开始安装IE高拍仪驱动【高拍仪控件下载.exe】……")    If FileExists($file_e) Then    Run($file_e)    WinwaitActive($e,"")    ControlSetText($e, "目标文件夹(&D)", "Edit1", "C:\gaopaiyi_ie" )     Send("{ENTER}")    Send("!I")    ;WinwaitActive($e,"安装完毕")    ;WinActivate($e,"安装完毕")    Sleep(2000)    ControlClick("RegSvr32","确定","Button1")    _FileWriteLog($logFileName,"IE高拍仪驱动安装成功!")    MsgBox(0, "提示信息", "IE高拍仪驱动安装成功",2)    Else       MsgBox(0, "提示信息", "未找到安装文件,安装失败!",1)       _FileWriteLog($logFileName,"未找到安装文件,安装失败!")    EndIfEndFunc     

自动卸载代码块

Func uninstallIE($logFileName)    $autoItDir = "C:\gaopaiyi_ie"    $filelist = _FileListToArray ($autoItDir)    if $filelist==0 then        _FileWriteLog($logFileName,"系统还未安装【IE高拍仪驱动】")    else        DirRemove($autoItDir,1)        _FileWriteLog($logFileName,"IE高拍仪驱动文件已删除!")    endifEndFunc

记录日志

#include <file.au3>$logFileName=@ScriptDir & "/" & "InstallLog.txt"$osversion=@OsVersionIf FileExists( $logFileName ) Then   FileDelete($logFileName)EndIf_FileWriteLog($logFileName,"开始卸载所有驱动……")