[以解决]运行一个循环,如何在失败或者取消后不运行一段程序。
本帖最后由 三月鸟 于 2013-3-25 14:25 编辑大概的原理是遍历添加删除程序,如果发现程序已经安装就弹出对话框询问是否卸载。
如果根本没有这个程序或者已经卸载后再运行安装程序。
可是现在的情况是如果不卸载或者等待时间过后,循环完毕了。还是会运行安装代码。
这安装代码放哪都不合适。。。。应该是用一个条件选择语句,可是不是学编程的,真转不过这个弯来。。。
大家帮忙参谋参谋。。。$bigfix = IniRead("Settings.ini", "address", "bigfix", "\\\share\packages\BigFixClient\setup.exe")
Local $iMsgBoxAnswer , $data = '', $temp, $i = 1, $uninstall = 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
While 1
$key = RegEnumKey($uninstall, $i)
$temp = RegRead($uninstall & '\' & $key, 'DisplayName')
If $temp = 'Tivoli Endpoint Manager Client' Then
$data= RegRead($uninstall & '\' & $key, 'UninstallString')
$iMsgBoxAnswer = MsgBox(33, "Bigfix Client has been installed.", "Please confirm Bigfix Client version, Uninstall Bigfix Client Click 'OK'", 15)
Select
Case $iMsgBoxAnswer = 1 ;OK
RunWait($data)
Case $iMsgBoxAnswer = 2 ;Cancel
Case $iMsgBoxAnswer = -1 ;Timeout
EndSelect
ExitLoop
EndIf
$i += 1
WEnd
;上面的是判断软件是否安装,如果安装就卸载。下面的是重新安装脚本。如果选择不卸载,下面的安装还是会被执行,如果放到循环里面,未安装的机器就不会安装。。。。
ShellExecute($bigfix)
WinWaitActive("Tivoli Endpoint Manager Client - InstallShield Wizard","Welcome to the InstallShield Wizard for Tivoli Endpoint Manager Client")
Send("!N")
WinWaitActive("Tivoli Endpoint Manager Client - InstallShield Wizard","Destination Folder")
Send("!N")
WinWaitActive("Tivoli Endpoint Manager Client - InstallShield Wizard","InstallShield Wizard Complete")
Send("!F") Local $bigfix = IniRead('Settings.ini', 'address', 'bigfix', '\\\share\packages\BigFixClient\setup.exe')
Local $iMsgBoxAnswer, $key, $data = '', $temp, $i = 1
Local $uninstall = 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
While 1
$key = RegEnumKey($uninstall, $i)
If $key = '' Then ExitLoop
$temp = RegRead($uninstall & '\' & $key, 'DisplayName')
If $temp = 'Tivoli Endpoint Manager Client' Then
$data = RegRead($uninstall & '\' & $key, 'UninstallString')
$iMsgBoxAnswer = MsgBox(33, 'Bigfix Client has been installed.', _
'Please confirm Bigfix Client version, Uninstall Bigfix Client Click 'OK'', 15)
If $iMsgBoxAnswer = 1 Then ;OK
RunWait($data)
__Install()
EndIf
ExitLoop
EndIf
$i += 1
WEnd
Func __Install()
ShellExecute($bigfix)
WinWaitActive('Tivoli Endpoint Manager Client - InstallShield Wizard', 'Welcome to the InstallShield Wizard for Tivoli Endpoint Manager Client')
Send('!N')
WinWaitActive('Tivoli Endpoint Manager Client - InstallShield Wizard', 'Destination Folder')
Send('!N')
WinWaitActive('Tivoli Endpoint Manager Client - InstallShield Wizard', 'InstallShield Wizard Complete')
Send('!F')
EndFUnc ;==>__Install 程序安装的键名一般是固定的吧。如是的话,可直接读取其UninstallString的值,如为空,说明没安装,不空的话就是已经安装了,再询问是否要先卸载。 这软件有几个版本。键值应该有区别。
我想了想,应该是先遍历出来键值的变量。然后把安装什么的单独提出来。
我先弄弄试试。 大概是这个意思。。。我试试行不行。Local $bigfix = IniRead('Settings.ini', 'address', 'bigfix', 'd:\BigFixClient\setup.exe')
Local $iMsgBoxAnswer, $key, $data = '', $temp, $i = 1
Local $uninstall = 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
Func __Install()
ShellExecute($bigfix)
WinWaitActive('Tivoli Endpoint Manager Client - InstallShield Wizard', 'Welcome to the InstallShield Wizard for Tivoli Endpoint Manager Client')
Send('!N')
WinWaitActive('Tivoli Endpoint Manager Client - InstallShield Wizard', 'Destination Folder')
Send('!N')
WinWaitActive('Tivoli Endpoint Manager Client - InstallShield Wizard', 'Ready to Install the Program')
Send('!I')
WinWaitActive('Tivoli Endpoint Manager Client - InstallShield Wizard', 'InstallShield Wizard Complete')
Send('!F')
EndFUnc ;==>__Install
While 1
$key = RegEnumKey($uninstall, $i)
If $key = '' Then ExitLoop
$temp = RegRead($uninstall & '\' & $key, 'DisplayName')
If $temp = 'Tivoli Endpoint Manager Client' Then
$data = RegRead($uninstall & '\' & $key, 'UninstallString')
ExitLoop
EndIf
$i += 1
WEnd
If $data = ""Then
__Install()
Else
$iMsgBoxAnswer = MsgBox(33, 'Bigfix Client has been installed.',"Please confirm Bigfix Client version, Uninstall Bigfix Client Click 'OK'", 15)
If $iMsgBoxAnswer = 1 Then ;OK
MsgBox(4096, "warning", $data, 5)
RunWait($data)
__Install()
EndIf
EndIf
我最开始脑子没转过来,想把所有的事情在循环里面解决。
其实循环里面把变量赋值了,之后检测一下变量就可以爱怎么用怎么用了。。。
多谢版主回复,多谢楼上的提醒。
页:
[1]