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 36 37 38 39 40 41 42 43 44
|
function TFrMfMain.RunExternEx(value: string; FlagAdmin: boolean = false; aparam: string = ''): boolean;var
SEInfo : TShellExecuteInfoW;
IdResult: DWORD;
FlagNoWait: boolean;
begin
result:= false;
try
ZeroMemory(@SEInfo, SizeOf(SEInfo));
with SEInfo do begin
cbSize := SizeOf(SEInfo);
fMask:= SEE_MASK_NOCLOSEPROCESS;
Wnd:= 0;
lpFile:= PChar(value);//value contient les chemin et nom du fichier
if aparam <> '' then
lpParameters:= pchar(aParam);
lpDirectory:= nil;
if FlagAdmin then
lpVerb:= 'runas';
nShow:= SW_SHOWMAXIMIZED;
end;
FlagNoWait:= false;
if ShellExecuteEx(@SEInfo) then begin
repeat
IdResult:= Winapi.Windows.WaitForSingleObject(SEInfo.hProcess, 200);
case IdResult of
WAIT_ABANDONED: FlagNoWait:= true;
WAIT_OBJECT_0: result:= true;
WAIT_FAILED:
begin
FlagNoWait:= true;
if GetLastError = 6 then
saveMsg('Gestion automatique non prise en compte, il n''y aura pas de sauvegarde automatique !')
else
savemsg(syserrormessage(GetlastError));
end;
end;
application.ProcessMessages;
until result or FlagNoWait;
end else savemsg(inttostr(GetlastError));
except
savemsg('RunExternEx ' + exception(exceptobject).Message);
end;
end; |
Partager