Non, le ShellExecute peut s'utiliser de différentes manières :
Comme ça
Avec cette solution on attend la sortie du process lancé par ShellExecuteCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 function ShellProcess(Filename : string; Parameters : string ='' ) : Boolean; var SEInfo : TShellExecuteInfo; ExitCode : DWORD; StartPath : string; begin FillChar(SEInfo, SizeOf(SEInfo), 0) ; SEInfo.cbSize := SizeOf(TShellExecuteInfo) ; with SEInfo do begin fMask := SEE_MASK_NOCLOSEPROCESS; Wnd := Application.Handle; lpFile := PChar(Filename); if Parameters<>'' then begin lpParameters := PChar(Parameters); end; StartPath:=ExtractFilePath(Filename); if StartPath<>'' then begin lpDirectory := PChar(StartPath); end; nShow := SW_SHOWNORMAL; end; Result:=False; if ShellExecuteEx(@SEInfo) then begin repeat GetExitCodeProcess(SEInfo.hProcess, ExitCode) ; Sleep(100); until (ExitCode <> STILL_ACTIVE); Result:=(ExitCode=0); end; end;
Et de cette façon on n'attend pas la sortie du process, on aura juste une valeur d'erreur, par exemple si le fichier n'existe pasCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 function ShellProcessAndDetach(Filename : string; Parameters : string ='' ) : Integer; var SEInfo : TShellExecuteInfo; ExitCode : DWORD; StartPath : string; begin FillChar(SEInfo, SizeOf(SEInfo), 0) ; SEInfo.cbSize := SizeOf(TShellExecuteInfo) ; with SEInfo do begin fMask := SEE_MASK_NOCLOSEPROCESS; Wnd := Application.Handle; lpFile := PChar(Filename); if Parameters<>'' then begin lpParameters := PChar(Parameters); end; StartPath:=ExtractFilePath(Filename); if StartPath<>'' then begin lpDirectory := PChar(StartPath); end; nShow := SW_SHOWNORMAL; end; Result:=WAIT_FAILED; if ShellExecuteEx(@SEInfo) then begin Sleep(100); GetExitCodeProcess(SEInfo.hProcess, ExitCode) ; Result:=ExitCode; end; end;