index_swf 发表于 2011-1-30 16:10:11

我自己用的软件自动安装模板

这个脚本的优点在于方便!用了就知道!#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_UseUPX=n
;禁止UPX压缩,防误报
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****

Const $ProductName = "WisMencoder 2.3 AVS 核心版"
;这行用于定义程序名,安装完成后弹出提示

Local $CurrWinTitle, $CurrWinText
;声明变量

RegDelete("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{052CFB79-9D62-42E3-8A15-DE66C2C97C3E}")
;用于删除软件安装信息,以防弹出**已安装的提示

ShellExecute(@ScriptDir & "\AcronisDiskDirector.msi")
;用于运行非可执行安装包

Run("kmplayer2010.exe")
;用于运行可执行安装包

_AutoCheckWindows("KMPlayer中文版 2010 安装", "选定安装的组件: ")
;这是我自定义的函数,用于激活当前窗口,并把窗口标题和窗口文本赋给变量$CurrWinTitle, $CurrWinText,方便对窗口进行操作
;相信大家一看就明白,第三个参数可选,为超时时间,单位秒

;注意:一下一些代码都是处理控件用的,控件id请自行修改,并参照帮助
ControlFocus ($CurrWinTitle, $CurrWinText, "")
ControlTreeView($CurrWinTitle, $CurrWinText, "", "Select", "#3")
ControlSend($CurrWinTitle, $CurrWinText, "", "{Space}")
;以上三行代码用于处理如图1所示的树形列表框

ControlClick($CurrWinTitle, $CurrWinText, "")
;用于对按钮发送单击事件

ControlSend($CurrWinTitle, $CurrWinText, "", "VGBEZ-WZFBU-2C9YU-7WQRK-3NZLB")
;用于向文本框发送字符串,不支持中文,可以用来发送SN,如图2

ControlCommand($CurrWinTitle, $CurrWinText, "", "UnCheck", "")
;用于取消选中某些复选框,例如“运行。。。”

ControlCommand($CurrWinTitle, $CurrWinText, "", "UnCheck", "")
;用于选中某些复选框,例如“我同意。。。”

MsgBox(64, "提示", $ProductName & " 安装完成!", 1)
;弹出提示


Func _AutoCheckWindows($WinTitle, $WinText, $TimeOut = 0)
        $CurrWinTitle = $WinTitle
        $CurrWinText = $WinText
        WinWait($WinTitle, $WinText, $TimeOut)
        If Not WinActive($WinTitle, $WinText) Then WinActivate($WinTitle, $WinText)
        WinWaitActive($WinTitle, $WinText, $TimeOut)
EndFunc   ;==>_AutoCheckWindows




再发一个例子,暴风影音自动安装脚本#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_UseUPX=n
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****

Local Const $Reg_Firewall = "HKLM\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile\AuthorizedApplications\List"
Local Const $Reg_Uninstall = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\storm2"

Local $TargetPath = @ProgramFilesDir & "\StormII\"
Local $KeyValue = RegRead($Reg_Uninstall, "UninstallString")
Local $Str_Tmp1 = StringSplit($KeyValue, "\")
Local $Str_Tmp2 = StringTrimRight($KeyValue, StringLen($Str_Tmp1[$Str_Tmp1]) + 1)
If $Str_Tmp2 <> "" Then $TargetPath = $Str_Tmp2

RegWrite($Reg_Firewall, $TargetPath & "\box\Stline.exe", "REG_SZ", $TargetPath & "\box\Stline.exe:*:Disabled:暴风盒子")
RegWrite($Reg_Firewall, $TargetPath & "\Storm.exe", "REG_SZ", $TargetPath & "\Storm.exe:*:Disabled:暴风影音")
RegWrite($Reg_Firewall, $TargetPath & "\Stormtray.exe", "REG_SZ", $TargetPath & "\Stormtray.exe:*:Disabled:暴风影音的伺服托盘程序,用于快速访问进入电脑的新媒体文件以及打开暴风影音软件")
RegWrite($Reg_Firewall, $TargetPath & "\StormUpdate.dll", "REG_SZ", $TargetPath & "\StormUpdate.dll:*:Disabled:暴风影音媒体控制中心")
RegWrite($Reg_Firewall, $TargetPath & "\stormliv.exe", "REG_SZ", $TargetPath & "\stormliv.exe:*:Enabled:暴风影音媒体控制中心")
RegWrite($Reg_Firewall, $TargetPath & "\stormpop.exe", "REG_SZ", $TargetPath & "\stormpop.exe:*:Disabled:暴风影音资源组件")
;Disable xp firewall
;Declare

RegDelete($Reg_Run, "Stormtray")
;Delete autorun

ProcessClose("storm.exe")
ProcessClose("stormtray.exe")
ProcessClose("stline.exe")
ProcessClose("StormUpdate.exe")
ProcessClose("stormpop.exe")
ProcessClose("BugReport.exe")
;Kill process

_DelFileAndPreventReBuild($TargetPath & "\media\stcon.ini")
_DelFileAndPreventReBuild($TargetPath & "\media\video_style_list.xml")
_DelFileAndPreventReBuild($TargetPath & "\Stormtray.exe")
_DelFileAndPreventReBuild($TargetPath & "\stormpop.exe")
;Delete Files

_RemoveDirAndPreventReBuild(@AppDataCommonDir & "\Storm\md")
_RemoveDirAndPreventReBuild(@AppDataCommonDir & "\Storm\box")
_RemoveDirAndPreventReBuild($TargetPath & "\box")
;Remove Dirtorys

Local $CurrWinTitle, $CurrWinText

RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\storm2")
Run("暴风影音2012.exe")

_AutoCheckWindows("安装 暴风影音2012", "欢迎安装 暴风影音2012")
ControlClick($CurrWinTitle, $CurrWinText, "")

_AutoCheckWindows($CurrWinTitle, "许可证协议")
ControlClick($CurrWinTitle, $CurrWinText, "")

_AutoCheckWindows($CurrWinTitle, "选择组件和需要创建的快捷方式")
ControlClick($CurrWinTitle, $CurrWinText, "")

_AutoCheckWindows($CurrWinTitle, "选择安装位置")
ControlClick($CurrWinTitle, $CurrWinText, "")

_AutoCheckWindows($CurrWinTitle, "免费的百度工具栏")
ControlCommand($CurrWinTitle, $CurrWinText, "", "UnCheck", "")
ControlClick($CurrWinTitle, $CurrWinText, "")

_AutoCheckWindows($CurrWinTitle, "暴风影音2012 安装完成")
ControlCommand($CurrWinTitle, $CurrWinText, "", "UnCheck", "")
ControlClick($CurrWinTitle, $CurrWinText, "")

FileDelete(@StartMenuCommonDir & "\程序\暴风影音\暴风游戏.lnk")
FileDelete(@StartMenuCommonDir & "\程序\暴风影音\免费影视.lnk")
FileDelete(@DesktopDir & "\暴风游戏.lnk")
FileDelete(@DesktopDir & "\免费影视.lnk")
;Delete shortcut

MsgBox(64, "提示", "暴风影音2012 安装完成!", 1)

Func _AutoCheckWindows($WinTitle, $WinText, $TimeOut = 0)
        $CurrWinTitle = $WinTitle
        $CurrWinText = $WinText
        WinWait($WinTitle, $WinText, $TimeOut)
        If Not WinActive($WinTitle, $WinText) Then WinActivate($WinTitle, $WinText)
        WinWaitActive($WinTitle, $WinText, $TimeOut)
EndFunc   ;==>_AutoCheckWindows

dmqhcx88 发表于 2011-1-30 16:45:54

有空了再试下,

734182531 发表于 2011-1-30 19:01:53

试下!看下好吗?

guotieyun 发表于 2011-3-4 16:18:02

这个不错 谢了

浪迹红客 发表于 2011-3-6 08:35:42

收下了·,谢谢楼主

dalao 发表于 2011-4-18 15:29:20

辛苦楼主了 试一下

pk2910 发表于 2011-4-21 15:09:41

果然够强大。留了

fenghua231 发表于 2011-4-22 01:33:13

始终没懂,还要自己手动修改?????

zm5268 发表于 2011-4-22 21:26:22

辛苦楼主了, 试一下。。。

真彩蘑菇 发表于 2011-4-24 14:55:58

收藏,回头试试看.....谢谢楼主

wa18239 发表于 2011-7-23 19:17:08

虽然不是都能看懂,不过还是谢谢楼主的倾情奉献{:face (88):}

mefcl 发表于 2011-7-24 18:10:10

不错啊,谢谢了

719931662 发表于 2011-7-30 19:02:25

#NoTrayIcon
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Opt("TrayOnEventMode", 1)
Opt("guicloseonesc", 0)
;以下为检查配置文件设置
$soft_ini = FileOpen("Soft.ini", 0)
If $soft_ini = -1 Then
MsgBox(16, "错误", '请检查配置文件' & @ScriptDir & '\"Soft.ini"是否存在!') ;@ScriptDir为脚本所在目录
Exit
EndIf

FileClose($soft_ini)
;以下为定义变量和常量
Const $N = 11, $s = 5
Dim $softname[$N], $softPath[$N], $soft[$N], $radio[$s], $InstallPath
;以下为读取soft.ini配置文件的函数
$title = IniRead("soft.ini", "form", "title", "")
$top_pic = IniRead("soft.ini", "form", "Top_pic", "")
$time = IniRead("soft.ini", "form", "time", "")
$state = IniRead("soft.ini", "form", "state", "")
;以下为依次从配置文件读取软件名、路径的循环
For $i = 0 To $N - 1
$softname[$i] = IniRead("soft.ini", $i, "softname", "空")
$softPath[$i] = IniRead("soft.ini", $i, "softpath", "空")
;msgbox(4096,"测试变量传递",$softname[$i]&$softPath[$i])
Next
;以下为创建主窗体
$form = GUICreate($title, 480, 360, -1, -1)
$top_pic = GUICtrlCreatePic($top_pic, 0, 0, 480, 90)
$Group1 = GUICtrlCreateGroup("", 10, 90, 460, 120)
;在GUI上创建10个复选框(Checkbox)控件,软件名称从配置文件里读取
$soft = GUICtrlCreateCheckbox("&1 " & $softname, 15, 100, 225, 20)
$soft = GUICtrlCreateCheckbox("&2 " & $softname, 15, 120, 225, 20)
$soft = GUICtrlCreateCheckbox("&3 " & $softname, 15, 140, 225, 20)
$soft = GUICtrlCreateCheckbox("&4 " & $softname, 15, 160, 225, 20)
$soft = GUICtrlCreateCheckbox("&5 " & $softname, 15, 180, 225, 20)
$soft = GUICtrlCreateCheckbox("&6 " & $softname, 240, 100, 225, 20)
$soft = GUICtrlCreateCheckbox("&7 " & $softname, 240, 120, 225, 20)
$soft = GUICtrlCreateCheckbox("&8 " & $softname, 240, 140, 225, 20)
$soft = GUICtrlCreateCheckbox("&9 " & $softname, 240, 160, 225, 20)
$soft = GUICtrlCreateCheckbox("&0 " & $softname, 240, 180, 225, 20)
For $i = 0 To $N - 1
$start1 = GUICtrlSetState($soft[$i], $GUI_DISABLE)
Next
$Group2 = GUICtrlCreateGroup("安装方式", 10, 215, 200, 70)
;从配置文件里读取安装的名称
$setA = IniRead("soft.ini", "select", "A", "")
$chooseA = IniRead("soft.ini", "select", "ChooseA", "")
$setB = IniRead("soft.ini", "select", "B", "")
$chooseB = IniRead("soft.ini", "select", "ChooseB", "")
$setC = IniRead("soft.ini", "select", "C", "")
$chooseC = IniRead("soft.ini", "select", "ChooseC", "")
$setD = IniRead("soft.ini", "select", "D", "")
$chooseD = IniRead("soft.ini", "select", "ChooseD", "")
;创建4个单选按钮,名称从配置文件里读取
$radio = GUICtrlCreateRadio($setA & "(&A)", 20, 230, 70, 20)
$radio = GUICtrlCreateRadio($setB & "(&B)", 20, 260, 70, 20)
$radio = GUICtrlCreateRadio($setC & "(&C)", 120, 230, 70, 20)
$silent = GUICtrlSetState($radio, $GUI_CHECKED)
$silent = propose()
$radio = GUICtrlCreateRadio($setD & "(&D)", 120, 260, 70, 20)
For $i = 0 To $s - 1
$start2 = GUICtrlSetState($radio[$i], $GUI_DISABLE)
Next
$Group3 = GUICtrlCreateGroup("安装目录", 215, 215, 255, 70)
$InstallPath = "C:\Program Files"
$input1 = GUICtrlCreateInput($InstallPath, 220, 245, 160, 20)
$start3 = GUICtrlSetState($input1, $GUI_DISABLE)
$Button1 = GUICtrlCreateButton("浏览(&O)", 400, 245, 60, 20)
$start4 = GUICtrlSetState($Button1, $GUI_DISABLE)
$Labtime = GUICtrlCreateLabel("", 10, 295, 165, 20, $WS_EX_STATICEDGE)
$pro = GUICtrlCreateProgress(10, 310, 280, 20)
$Button2 = GUICtrlCreateButton("手动选择(&X)", 300, 310, 80, 20)
$Button3 = GUICtrlCreateButton("开始安装(&S)", 390, 310, 80, 20)
$copyright = GUICtrlCreateLabel("浪人阿俊软件自动安装器 qq659552987", 220, 345, 300, 20)
$start5 = GUICtrlSetState($copyright, $GUI_DISABLE)
If $state = 1 Or $state = "" Then
GUISetState(@SW_SHOW)
ElseIf $state = 0 Then
GUISetState(@SW_HIDE)
EndIf
;以下为倒计时设置
AdlibEnable("pro1", 10 * $time)
$wait = 0
Func pro1()
$start6 = GUICtrlSetData($pro, $wait)
For $v = 0 To $time Step 1
   If GUICtrlRead($pro) = $v * 10 / ($time / 10) Then GUICtrlSetData($Labtime, $time - $v & "秒后自动安装所选项")
Next
$wait = $wait + 1
If $wait = 101 Then AZ()
EndFunc ;==>pro1
;以下为设置窗口事件
While 1
$nMsg = GUIGetMsg()
Select
   Case $nMsg = $GUI_EVENT_CLOSE
AdlibDisable()
ExitLoop
   Case $nMsg = $radio And BitAND(GUICtrlRead($radio), $GUI_CHECKED) = $GUI_CHECKED
$all = all()
   Case $nMsg = $radio And BitAND(GUICtrlRead($radio), $GUI_CHECKED) = $GUI_CHECKED
$none = none()
   Case $nMsg = $radio And BitAND(GUICtrlRead($radio), $GUI_CHECKED) = $GUI_CHECKED
$propose = propose()
   Case $nMsg = $radio And BitAND(GUICtrlRead($radio), $GUI_CHECKED) = $GUI_CHECKED
$small = small()
   Case $nMsg = $Button1
$open = open()
   Case $nMsg = $Button2
$XZ = XZ()
   Case $nMsg = $Button3
$AZ = AZ()
EndSelect
WEnd
;全部选中
Func all()
AdlibDisable()
For $i = 0 To $N - 1
   If $softname[$i] And $softPath[$i] <> "" Then
GUICtrlSetState($soft[$i], $GUI_CHECKED)
   Else
GUICtrlSetState($soft[$i], $GUI_UNCHECKED)
   EndIf
Next
EndFunc ;==>all
;全部不选
Func none()
AdlibDisable()
For $i = 0 To $N - 1
   If $softname[$i] And $softPath[$i] <> "" Then
GUICtrlSetState($soft[$i], $GUI_UNCHECKED)
   Else
GUICtrlSetState($soft[$i], $GUI_UNCHECKED)
   EndIf
Next
EndFunc ;==>none
;推荐安装
Func propose()
AdlibDisable()
For $i = 0 To $N - 1
   If StringInStr(String($chooseC), $i) Then
If $softname[$i] And $softPath[$i] <> "" Then
GUICtrlSetState($soft[$i], $GUI_CHECKED)
Else
GUICtrlSetState($soft[$i], $GUI_UNCHECKED)
EndIf
   Else
GUICtrlSetState($soft[$i], $GUI_UNCHECKED)
   EndIf
Next
EndFunc ;==>propose
;最少安装
Func small()
AdlibDisable()
none()
For $i = 0 To $N - 1
   If StringInStr(String($chooseD), $i) Then
If $softname[$i] And $softPath[$i] <> "" Then
GUICtrlSetState($soft[$i], $GUI_CHECKED)
Else
GUICtrlSetState($soft[$i], $GUI_UNCHECKED)
EndIf
   EndIf
Next
EndFunc ;==>small
;设置安装目录
Func open()
AdlibDisable()
$InstallPath = FileSelectFolder("选择安装目录", "")
If Not @error Then
   If StringRight($InstallPath, 1) = "\" Then
GUICtrlSetData($input1, $InstallPath & "")
   Else
GUICtrlSetData($input1, $InstallPath & "\")
   EndIf
   ;MsgBox(4096, "测试", $InstallPath)
EndIf
EndFunc ;==>open
;设置选择
Func XZ()
AdlibDisable()
GUICtrlSetData($Labtime, "*手动选择*")
For $i = 0 To $N - 1
   GUICtrlSetState($soft[$i], $GUI_ENABLE)
   GUICtrlSetState($input1, $GUI_ENABLE)
   GUICtrlSetState($Button1, $GUI_ENABLE)
   GUICtrlSetState($radio, $GUI_ENABLE)
   GUICtrlSetState($radio, $GUI_ENABLE)
   GUICtrlSetState($radio, $GUI_ENABLE)
   GUICtrlSetState($radio, $GUI_ENABLE)
Next
EndFunc ;==>XZ
;设置安装
Func AZ()
AdlibDisable()
GUICtrlSetData($Labtime, "*安装所选*")
For $i = 0 To $N - 1
   If $softPath[$i] <> "" And GUICtrlRead($soft[$i]) = $GUI_CHECKED Then
RunWait(@ScriptDir & "\" & $softPath[$i] & " " & $InstallPath)
;MsgBox(4096, "测试",@ScriptDir & "\" & $softPath[$i]&$InstallPath)
   Else
GUICtrlSetState($soft[$i], $GUI_DISABLE)
   EndIf
Next
Exit
EndFunc ;==>AZ

bluesky4485 发表于 2011-7-31 14:00:37

得仔细看看脚本啊,不然不明白。新手

yysnowman732 发表于 2011-8-8 09:59:21

学习先,谢谢分享。
页: [1] 2
查看完整版本: 我自己用的软件自动安装模板