1 | #Include <File.au3> |
---|
2 | AdlibRegister( "Unexpected" ) |
---|
3 | $mytop = @DesktopHeight - 50 - 60 |
---|
4 | $myleft = (@DesktopWidth / 2) - 150 |
---|
5 | |
---|
6 | SplashTextOn ( "Mercury MasterLink Automatic Installation", "Please do not touch the mouse or keyboard until the installation is complete.", 400, 60 , $myleft, $mytop, -1, "", 10 ) |
---|
7 | |
---|
8 | global $OUTPUT |
---|
9 | global $logfullpath |
---|
10 | |
---|
11 | |
---|
12 | $OUTPUT = 0 |
---|
13 | |
---|
14 | if $CmdLine[0] >= 1 then |
---|
15 | $OUTPUT = 1 |
---|
16 | |
---|
17 | $logfullpath = $CmdLine[1] |
---|
18 | |
---|
19 | $array = StringSplit($CmdLine[1], "\\") |
---|
20 | $logname = $array[$array[0]] |
---|
21 | $logpath = stringleft($logfullpath, stringlen($logfullpath) - stringlen($logname) - 1) |
---|
22 | |
---|
23 | ; if ($logpath = "") then only a log name was supplied not the log path |
---|
24 | if ($logpath = "") or (fileexists($logpath)) then |
---|
25 | fileopen($logfullpath, 2) |
---|
26 | fileclose($logfullpath) |
---|
27 | else |
---|
28 | msgbox(1,"","Log path not found") |
---|
29 | exit(2) |
---|
30 | endif |
---|
31 | endif |
---|
32 | |
---|
33 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Running MtrLnk32.Exe") |
---|
34 | run("MtrLnk32.Exe") |
---|
35 | |
---|
36 | |
---|
37 | ; if I remove this |
---|
38 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for License Agreement window") |
---|
39 | WaitForWindow("License Agreement", "") |
---|
40 | send("{ENTER}") |
---|
41 | ; add |
---|
42 | ; if winexists("License Agreement", "") then |
---|
43 | ; winactivate("License Agreement", "") |
---|
44 | ; send("{ENTER}") |
---|
45 | ; EndIf |
---|
46 | ; to the Unexpected() function, the windows is found and dealt with but |
---|
47 | ; then it times out on the next window. |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Welcome window") |
---|
52 | WaitForWindow("MasterLink32", "This installation program will install") |
---|
53 | send("!n") |
---|
54 | |
---|
55 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Registration window") |
---|
56 | WaitForWindow("MasterLink32", "Please enter the name and company") |
---|
57 | send("...") |
---|
58 | send("{TAB}") |
---|
59 | send("...") |
---|
60 | Send("{TAB}") |
---|
61 | Send("ML459") |
---|
62 | send("!n") |
---|
63 | |
---|
64 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Registration Confirmation window") |
---|
65 | WaitForWindow("MasterLink32", "Please verify") |
---|
66 | send("!n") |
---|
67 | |
---|
68 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Select Destination window") |
---|
69 | WaitForWindow("MasterLink32", "Select Destination") |
---|
70 | send("!r") |
---|
71 | |
---|
72 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Enter Destination window") |
---|
73 | WaitForWindow("Select Destination", "") |
---|
74 | send("C:\Programs\Mercury32") |
---|
75 | send("{ENTER}") |
---|
76 | |
---|
77 | sleep(5000) |
---|
78 | send("!n") |
---|
79 | |
---|
80 | sleep(10000) |
---|
81 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Database window") |
---|
82 | WaitForWindow("MasterLink32", "unable to locate a database") |
---|
83 | send("!r") |
---|
84 | |
---|
85 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Enter Destination window") |
---|
86 | WaitForWindow("Select Destination", "") |
---|
87 | send("C:\Programs\Mercury32\Data") |
---|
88 | send("{ENTER}") |
---|
89 | |
---|
90 | sleep(5000) |
---|
91 | controlcommand("MasterLink32", "unable to locate a database", "[CLASS:Button; INSTANCE:6]", "Check", "") |
---|
92 | send("!n") |
---|
93 | |
---|
94 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Select ProgMan window") |
---|
95 | WaitForWindow("MasterLink32", "Select ProgMan") |
---|
96 | send("!n") |
---|
97 | |
---|
98 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Ready to Install window") |
---|
99 | WaitForWindow("MasterLink32", "Ready to Install") |
---|
100 | send("!n") |
---|
101 | |
---|
102 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Waiting for Installation Completed window") |
---|
103 | WaitForWindow("MasterLink32", "Installation Completed") |
---|
104 | send("!f") |
---|
105 | |
---|
106 | WinActivate("", "AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Mercury32") |
---|
107 | WinClose("Mercury32", "AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Mercury32") |
---|
108 | |
---|
109 | WinActivate("", "AppData\Roaming\Microsoft\Windows\Start Menu\Programs") |
---|
110 | WinClose("Mercury32", "AppData\Roaming\Microsoft\Windows\Start Menu\Programs") |
---|
111 | |
---|
112 | unexpected() |
---|
113 | |
---|
114 | if $OUTPUT = 1 then _FileWriteLog($logfullpath, "Installation Complete. Return code = 0") |
---|
115 | Exit(0) |
---|
116 | |
---|
117 | Func unexpected() |
---|
118 | |
---|
119 | if winexists("Install", "already exists") then |
---|
120 | winactivate("Install", "already exists") |
---|
121 | send("{ENTER}") |
---|
122 | EndIf |
---|
123 | |
---|
124 | if winexists("MasterLink32", "Setup found a Mercury32 database") then |
---|
125 | winactivate("MasterLink32", "Setup found a Mercury32 database") |
---|
126 | send("!n") |
---|
127 | endif |
---|
128 | |
---|
129 | EndFunc |
---|
130 | |
---|
131 | |
---|
132 | Func Assert($n) |
---|
133 | If $n = 0 Then |
---|
134 | if $OUTPUT = 1 then |
---|
135 | _FileWriteLog($logfullpath, "Window not found") |
---|
136 | _FileWriteLog($logfullpath, "Found window: (" & WinGetTitle("[ACTIVE]", "") & ")") |
---|
137 | _FileWriteLog($logfullpath, "Window text:" & WinGetText("[ACTIVE]", "")) |
---|
138 | _FileWriteLog($logfullpath, "Installation failed. Return code = 1") |
---|
139 | endif |
---|
140 | Exit(1) |
---|
141 | endif |
---|
142 | EndFunc |
---|
143 | |
---|
144 | ; Wait for a window to exist, activate it, and wait for it to become active. |
---|
145 | ; If timeout expires while waiting, exit with a nonzero exit status. |
---|
146 | Func WaitForWindow($title, $text="", $timeout=60) |
---|
147 | Assert(WinWait($title, $text, $timeout)) |
---|
148 | WinActivate($title, $text) |
---|
149 | EndFunc |
---|
150 | |
---|