This would only be possible through another application, ie the application that will have to run as an administrator, you would need to run it through this other application. You would have to do a routine with a "Loop" to check if the other application was executed or not. If you make the other application (the call) in Delphi, the code would look like this:
//...
function processExists(exeFileName: string): Boolean;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
Result := False;
while Integer(ContinueLoop) <> 0 do
begin
if pos(UpperCase(exeFileName),UpperCase(FProcessEntry32.szExeFile)) > 0 then
exeFileName := FProcessEntry32.szExeFile;
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then
Result := True;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
//...
function CreateProcessSimple(cmd : string) : boolean;
var
suinfo: tstartupinfo;
procinfo: tprocessinformation;
begin
fillchar(suinfo, sizeof(suinfo),#0);
suinfo.cb := sizeof(suinfo);
suinfo.dwflags := startf_useshowwindow;
suinfo.wshowwindow := SW_HIDE;
result := createprocess(nil,
pchar(cmd),
nil,
nil,
false,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS,
nil,
nil,
suinfo,
procinfo);
if (result) then
begin
waitforsingleobject(procinfo.hprocess, INFINITE);
CloseHandle(procinfo.hprocess);
CloseHandle(procinfo.hthread);
end;
end;
//...
procedure BitBtn1Click(Sender: TObject);
begin
while not ProcessExists('AplicacaoAdmin.exe') do
CreateProcessSimple('AplicacaoAdmin.exe');
end;
Work your code as needed within the Loop so there is no crash.