You definitely don't want to use those kind of functions in this situation.
You don't need that. A process knows its own ID, you can query it directly.
You need something like this:
uses
..., Windows;
function RestartApp: Boolean;
var
si: STARTUPINFO;
pi: PROCESS_INFORMATION;
CmdLine: string;
begin
CmdLine := Format('"%s" /pid:%d', [ParamStr(0), GetCurrentProcessID()]);
ZeroMemory(@si, sizeof(si));
GetStartupInfo(@si);
Result := CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0, nil, nil, si, pi);
if Result then
begin
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
Application.Terminate;
end;
end;
Then in your app's startup code, such as in your main DPR file, you can do this before initializing your UI or anything else:
uses
..., Windows;
var
pid: string;
h: THandle;
begin
if FindCmdLineSwitch('pid', pid) then
begin
h := OpenProcess(SYNCHRONIZE, FALSE, StrToInt(pid));
if h <> 0 then
begin
WaitForSingleObject(h, INFINITE);
CloseHandle(h);
end;
end;
... continue starting up normally ...
end;