#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