找回密码
 加入
搜索
查看: 2461|回复: 13

自动安装时,如果关闭了安装文件,GUI中的按钮都点不动了

  [复制链接]
发表于 2009-12-2 00:27:50 | 显示全部楼层 |阅读模式
本帖最后由 xwt620 于 2009-12-3 22:50 编辑

RT,我估计是WinWaitActive 一直处于等待窗口被激活的状态,造成GUI中的按钮都点不动了。
想解决这种问题,我应该怎么做呢?

评分

参与人数 1金钱 +10 收起 理由
pusofalse + 10 感谢主动修改帖子分类为[已解决]。

查看全部评分

发表于 2009-12-2 02:18:51 | 显示全部楼层
自动安装   指的是什么?

这样的描述无法帮助你。。。。。。。。。。
发表于 2009-12-2 10:06:22 | 显示全部楼层
WinWaitActive()加个超时参数,超过多少就执行某代码
 楼主| 发表于 2009-12-2 19:35:03 | 显示全部楼层
我所说的自动安装是指,我编好的自动安装软件的脚本
加超时参数,我觉得不太理想
有时候有的安装程序在某一窗口停留很长时间
而且如果是不同的机器,配置不一样也会出错,那怎么办?
我的想法是在
While 1
     sleep(100)
Wend
里加个判断不知道可行不?
发表于 2009-12-2 19:41:59 | 显示全部楼层
WinWaitActive 的参数不是当前的窗口参数!而应是下一窗口的,。。。

没有脚本,看不出问题的。。。。。
发表于 2009-12-2 19:53:05 | 显示全部楼层
拿不准就用AdlibRegister及ProcessExists...
 楼主| 发表于 2009-12-2 22:05:16 | 显示全部楼层
本帖最后由 xwt620 于 2009-12-2 22:07 编辑

AdlibRegister偶还不太会用
我试下ProcessExists,看看行不行
 楼主| 发表于 2009-12-2 22:21:36 | 显示全部楼层
ProcessExists测试不成功
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("自动安装 MicroStation", 375, 186, @DesktopWidth / 3, @DesktopHeight / 3)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$Label1 = GUICtrlCreateLabel("安装文件路径:", 16, 32, 95, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
GUICtrlSetColor(-1, 0x0000FF)
$Input1 = GUICtrlCreateInput("Setup.exe", 112, 32, 201, 21)
$Button1 = GUICtrlCreateButton("浏览", 320, 32, 49, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "browse")
$Label2 = GUICtrlCreateLabel("软件安装路径:", 16, 72, 95, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
GUICtrlSetColor(-1, 0x0000FF)
$Input2 = GUICtrlCreateInput("C:\Program Files\Bentley", 112, 72, 201, 21)
$Button2 = GUICtrlCreateButton("浏览", 320, 72, 49, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "browse")
$Label3 = GUICtrlCreateLabel("运行状态:", 40, 112, 69, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
GUICtrlSetColor(-1, 0x0000FF)
$Label4 = GUICtrlCreateLabel("", 112, 112, 200, 17)
GUICtrlSetFont(-1, 10, 400, 0, "宋体")
GUICtrlSetColor(-1, 0x00FF00)
$Button3 = GUICtrlCreateButton("开始安装[&S]", 32, 144, 81, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "Setup")
$Button4 = GUICtrlCreateButton("手动注册[&R]", 152, 144, 83, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "AutoReg")
$Button5 = GUICtrlCreateButton("退  出[&X]", 272, 144, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "_Exit")
GUISetState(@SW_SHOW)
$done = 0
$setuping = 0

While 1
        Sleep(100)
;~         If ProcessExists('ustation.exe') Then ;修改状态
;~                 GUICtrlSetData($Label4, "MicroStation正在运行...", "")
;~         ElseIf $done = 1 Then
;~                 GUICtrlSetData($Label4, "安装完毕!", "")
;~         ElseIf $setuping = 1 Then
        If $setuping = 1 Then
;~                 GUICtrlSetData($Label4, "正在安装中,请稍后......", "")
                If Not ProcessExists('setup.exe') Then
;~                         GUICtrlSetData($Label4, "错误,安装程序意外停止", "")
                        $setuping = 0
                        MsgBox(0, '错误', '安装程序意外停止')
                EndIf
;~         Else
;~                 GUICtrlSetData($Label4, "待命中......", "")
        EndIf

WEnd

Func setup()
        $setup_exe = GUICtrlRead($Input1)
        $setup_folder = GUICtrlRead($Input2)
        If Not FileExists($setup_exe) Then
                MsgBox(0, '错误', '安装文件不存在,请选择正确的路径')
        Else

                Run($setup_exe)
                ProcessWait('setup.exe')
                $setuping = 1
                WinWaitActive("MicroStation Setup", "Welcome to the InstallShield Wizard for MicroStation")
                Send("!n")

                WinWaitActive("MicroStation Setup", "License Agreement")
                Send("!y")
                Send("!n")

                WinWaitActive("MicroStation Setup", "Choose Destination Location")
                ControlSetText("MicroStation Setup", "Choose Destination Location", 4, $setup_folder & "")
                Send("!n")

                WinWaitActive("MicroStation Setup", "Type of Installation")
                Send("!n")

                WinWaitActive("MicroStation Setup", "Select Components")
                Send("!n")

                WinWaitActive("MicroStation Setup", "InstallShield Wizard Complete")
                ControlClick("MicroStation Setup", "InstallShield Wizard Complete", 503)
                Send("{enter}")

                WinWaitActive("MicroStation Setup", "Setup has finished installing MicroStation on your computer.")
                Send("{enter}")
                Sleep(2000)
                $regfile = StringReplace($setup_exe, 'setup.exe', '')
                FileCopy($regfile & '\License\Keymaker.exe', $setup_folder & '\Program\Licensing', 1 + 8)
                $done = 1
                $setuping = 0
                $iAnswer = MsgBox(4 + 256 + 32, "注册", "软件需要注册,现在就注册吗?")
                Select
                        Case $iAnswer = 6 ;OK
                                AutoReg()
                        Case $iAnswer = 7 ;Cancel

                EndSelect
        EndIf
EndFunc   ;==>setup

Func AutoReg()
        $setup_folder = GUICtrlRead($Input2)
        $regfile = $setup_folder & '\Program\Licensing\Keymaker.exe'
        If Not FileExists($regfile) Then
                MsgBox(0, '错误', '注册机文件不存在,请手动选择注册机文件!')
                $regfile = FileOpenDialog("请选择MicroStation的注册机文件", @MyDocumentsDir, 'MicroStation 注册机文件 (Keymaker.exe)', 1 + 2)
                If @error Then
                        MsgBox(0, '注册失败!', '原因:未选择注册机文件!')
                Else
                        FileCopy($regfile, $setup_folder & '\Program\Licensing', 1 + 8)
                EndIf
        Else

                If Not ProcessExists('Keymaker.exe') Then Run($setup_folder & '\Program\Licensing\Keymaker.exe')
                If Not ProcessExists('ustation.exe') Then Run($setup_folder & '\Program\MicroStation\ustation.exe')
                $Pid = ProcessWait('Keymaker.exe', 60)
                If $Pid = 0 Then
                        MsgBox(0, '注册失败!', '原因:超时!')
                Else
                        WinActivate('C:\Program Files\Bentley\Program\Licensing\Keymaker.exe')
                        Send(@ComputerName)
                        Send('{ENTER}')

                        ProcessWaitClose($Pid)
                        ;生成的KEY文件和脚本文件同目录,估计是AUTOIT的BUG
                        $msg = FileMove("msv8.lic", $setup_folder & '\Program\Licensing\', 1 + 8)
                        If $msg = 0 Then
                                MsgBox(0, '错误', '注册软件失败')
                        Else
                                MsgBox(0, '成功', '注册软件成功')
                        EndIf
                EndIf
        EndIf

EndFunc   ;==>AutoReg

Func _Exit()
        $iAnswer = MsgBox(4 + 256 + 32, "确认", "是否退出程序?")
        Select
                Case $iAnswer = 6 ;OK
                        Exit 0
                Case $iAnswer = 7 ;Cancel

        EndSelect
EndFunc   ;==>_Exit

Func browse()
        Switch @GUI_CtrlId
                Case $Button1
                        $SFE = FileOpenDialog("请选择MicroStation的安装文件", @MyDocumentsDir, 'MicroStation 安装文件 (Setup.exe)', 1 + 2)
                        If @error Then
                                MsgBox(4096, "", "没有选择文件!")
                        Else
                                GUICtrlSetData($Input1, $SFE, "")
                        EndIf
                Case $Button2
                        $SF = FileSelectFolder("选择文件夹", "")
                        If @error Then
                                MsgBox(4096, "", "没有选择文件夹")
                                GUICtrlSetData($Input2, "C:\Program Files\Bentley", "")
                        Else
                                GUICtrlSetData($Input2, $SF, "")
                        EndIf
        EndSwitch
EndFunc   ;==>browse
发表于 2009-12-2 23:12:22 | 显示全部楼层
回复 8# xwt620


    你这样仍会停留在 WinWaitActive
 楼主| 发表于 2009-12-2 23:45:24 | 显示全部楼层
我把代码改为
Run($setup_exe)
ProcessWait('setup.exe')
AdlibRegister("Mysetup")
然后添加一个函数
Func Mysetup()
        If Not ProcessExists('setup.exe') Then
                MsgBox(0, '错误', '安装程序意外停止')
                AdlibUnRegister("Mysetup")
        EndIf
EndFunc   ;==>Mysetup

可还是不成功

看来问题就在WinWaitActive上了
发表于 2009-12-3 00:15:18 | 显示全部楼层
给你写了个函数,用它来替代 WinWaitActive 使用,试试吧
函数很简单,不用解释了吧
Func _WinWaitActive($exe, $title, $text, $timeout = 3000)
        Local $ii = 0
        While 1
                If ProcessExists($exe) = 0 Then Return 0
                If WinActive($title, $text) Then Return 1
                Sleep(100)
                $ii += 1
                If $ii = $timeout / 100 Then Return -1
        WEnd
EndFunc   ;==>_WinWaitActive
发表于 2009-12-3 00:21:22 | 显示全部楼层
解释下使用,比如
$test = _WinWaitActive($setup_exe, 'MicroStation Setup', 'Welcome to the InstallShield Wizard for MicroStation')
If $test = 1 then Send("!n")
If $test = 0 then Msgbox(0, 0, '安装程序已退出')
If $test = -1 then Msgbox(0, 0, '3000ms时间已到,目标窗口未出现')
 楼主| 发表于 2009-12-3 22:49:37 | 显示全部楼层
问题终于解决了
但是如果硬着头皮把每部都用Func _WinWaitActive来判断,如果中途安装程序退出,后面每一部都会弹出 安装程序已退出
后来我用Switch...Case,来回提交和判断,解决了弹出问题,只不过中间麻烦了许多
谢谢afan指导
发表于 2009-12-3 22:54:29 | 显示全部楼层
问题终于解决了
但是如果硬着头皮把每部都用Func _WinWaitActive来判断,如果中途安装程序退出,后面每一部 ...
xwt620 发表于 2009-12-3 22:49



    If $test = 0 then Return 就行了,后面的不会继续。要灵活应用。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-9 09:54 , Processed in 0.083364 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表