自动安装时,如果关闭了安装文件,GUI中的按钮都点不动了
本帖最后由 xwt620 于 2009-12-3 22:50 编辑RT,我估计是WinWaitActive 一直处于等待窗口被激活的状态,造成GUI中的按钮都点不动了。
想解决这种问题,我应该怎么做呢? 自动安装 指的是什么?
这样的描述无法帮助你。。。。。。。。。。 WinWaitActive()加个超时参数,超过多少就执行某代码 我所说的自动安装是指,我编好的自动安装软件的脚本
加超时参数,我觉得不太理想
有时候有的安装程序在某一窗口停留很长时间
而且如果是不同的机器,配置不一样也会出错,那怎么办?
我的想法是在
While 1
sleep(100)
Wend
里加个判断不知道可行不? WinWaitActive 的参数不是当前的窗口参数!而应是下一窗口的,。。。
没有脚本,看不出问题的。。。。。 拿不准就用AdlibRegister及ProcessExists... 本帖最后由 xwt620 于 2009-12-2 22:07 编辑
AdlibRegister偶还不太会用
我试下ProcessExists,看看行不行 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 回复 8# xwt620
你这样仍会停留在 WinWaitActive 我把代码改为
Run($setup_exe)
ProcessWait('setup.exe')
AdlibRegister("Mysetup")
然后添加一个函数
Func Mysetup()
If Not ProcessExists('setup.exe') Then
MsgBox(0, '错误', '安装程序意外停止')
AdlibUnRegister("Mysetup")
EndIf
EndFunc ;==>Mysetup
可还是不成功
看来问题就在WinWaitActive上了 给你写了个函数,用它来替代 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 解释下使用,比如$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时间已到,目标窗口未出现') 问题终于解决了
但是如果硬着头皮把每部都用Func _WinWaitActive来判断,如果中途安装程序退出,后面每一部都会弹出 安装程序已退出
后来我用Switch...Case,来回提交和判断,解决了弹出问题,只不过中间麻烦了许多
谢谢afan指导 问题终于解决了
但是如果硬着头皮把每部都用Func _WinWaitActive来判断,如果中途安装程序退出,后面每一部 ...
xwt620 发表于 2009-12-3 22:49 http://www.autoitx.com/images/common/back.gif
If $test = 0 then Return 就行了,后面的不会继续。要灵活应用。。。
页:
[1]