Rev 71 | Rev 79 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 71 | Rev 73 | ||
---|---|---|---|
Line 9... | Line 9... | ||
9 | {$INCLUDE 'UserDetect2.inc'} |
9 | {$INCLUDE 'UserDetect2.inc'} |
10 | 10 | ||
11 | uses |
11 | uses |
12 | Windows, SysUtils, Dialogs, ShellAPI; |
12 | Windows, SysUtils, Dialogs, ShellAPI; |
13 | 13 | ||
- | 14 | const |
|
- | 15 | EXITCODE_OK = 0; |
|
- | 16 | EXITCODE_TASK_NOTHING_MATCHES = 1; |
|
- | 17 | EXITCODE_RUN_FAILURE = 2; |
|
- | 18 | EXITCODE_TASK_NOT_EXISTS = 10; |
|
- | 19 | EXITCODE_INI_NOT_FOUND = 11; |
|
- | 20 | EXITCODE_RUNCMD_SYNTAX_ERROR = 12; |
|
- | 21 | EXTICODE_SYNTAX_ERROR = 13; |
|
- | 22 | ||
14 | type |
23 | type |
15 | TArrayOfString = array of String; |
24 | TArrayOfString = array of String; |
16 | 25 | ||
17 | TIconFileIdx = record |
26 | TIconFileIdx = record |
18 | FileName: string; |
27 | FileName: string; |
Line 145... | Line 154... | ||
145 | 154 | ||
146 | // Some errors have no error message, e.g. error 193 (BAD_EXE_FORMAT) in the German version of Windows 10 |
155 | // Some errors have no error message, e.g. error 193 (BAD_EXE_FORMAT) in the German version of Windows 10 |
147 | if result = '' then result := Format(LNG_UNKNOWN_ERROR, [ec]); |
156 | if result = '' then result := Format(LNG_UNKNOWN_ERROR, [ec]); |
148 | end; |
157 | end; |
149 | 158 | ||
150 | procedure CheckLastOSCall(AThrowException: boolean); |
159 | function CheckLastOSCall(AThrowException: boolean): boolean; |
151 | var |
160 | var |
152 | LastError: Cardinal; |
161 | LastError: Cardinal; |
153 | begin |
162 | begin |
154 | LastError := GetLastError; |
163 | LastError := GetLastError; |
- | 164 | result := LastError = 0; |
|
155 | if LastError <> 0 then |
165 | if not result then |
156 | begin |
166 | begin |
157 | if AThrowException then |
167 | if AThrowException then |
158 | begin |
168 | begin |
159 | RaiseLastOSError; |
169 | RaiseLastOSError; |
160 | end |
170 | end |
Line 221... | Line 231... | ||
221 | if p = 0 then |
231 | if p = 0 then |
222 | begin |
232 | begin |
223 | // No matching quotes |
233 | // No matching quotes |
224 | // CreateProcess() handles the whole command line as single file name ("abc -> "abc") |
234 | // CreateProcess() handles the whole command line as single file name ("abc -> "abc") |
225 | // ShellExecuteEx() does not accept the command line |
235 | // ShellExecuteEx() does not accept the command line |
- | 236 | ExitCode := EXITCODE_RUNCMD_SYNTAX_ERROR; |
|
226 | MessageDlg(LNG_INVALID_SYNTAX, mtError, [mbOK], 0); |
237 | MessageDlg(LNG_INVALID_SYNTAX, mtError, [mbOK], 0); |
227 | Exit; |
238 | Exit; |
228 | end; |
239 | end; |
229 | cmdFile := Copy(cmdLine, 1, p-1); |
240 | cmdFile := Copy(cmdLine, 1, p-1); |
230 | cmdArgs := Copy(cmdLine, p+2, Length(cmdLine)-p-1); |
241 | cmdArgs := Copy(cmdLine, p+2, Length(cmdLine)-p-1); |
Line 266... | Line 277... | ||
266 | if cmdArgs <> '' then sei.lpParameters := PChar(cmdArgs); |
277 | if cmdArgs <> '' then sei.lpParameters := PChar(cmdArgs); |
267 | if cmdDir <> '' then sei.lpDirectory := PChar(cmdDir); |
278 | if cmdDir <> '' then sei.lpDirectory := PChar(cmdDir); |
268 | sei.nShow := WindowMode; |
279 | sei.nShow := WindowMode; |
269 | if ShellExecuteEx(@sei) then Exit; |
280 | if ShellExecuteEx(@sei) then Exit; |
270 | {$IFNDEF PREFER_SHELLEXECUTEEX_MESSAGES} |
281 | {$IFNDEF PREFER_SHELLEXECUTEEX_MESSAGES} |
271 | CheckLastOSCall(false); |
282 | if not CheckLastOSCall(false) then ExitCode := EXITCODE_RUN_FAILURE; |
272 | {$ENDIF} |
283 | {$ENDIF} |
273 | end; |
284 | end; |
274 | 285 | ||
275 | function GetHTML(AUrl: string): string; |
286 | function GetHTML(AUrl: string): string; |
276 | // http://www.delphipraxis.net/post43515.html |
287 | // http://www.delphipraxis.net/post43515.html |