Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program test;
- {$APPTYPE GUI}
- uses
- Windows;
- const
- App_Title = 'Always use brain and google before ask!';
- function GetEnvVarValue(const VarName : string) : string;
- var
- BufSize : integer;
- begin
- BufSize := GetEnvironmentVariable(PChar(VarName), nil, 0);
- if BufSize > 0 then
- begin
- SetLength(Result, BufSize - 1);
- GetEnvironmentVariable(PChar(VarName), PChar(Result), BufSize);
- end
- else
- begin
- Result := '';
- end;
- end;
- var
- SI : TStartupInfo;
- PI : TProcessInformation;
- AppFullPath, SzCmd : string;
- SzModuleName : array[0..MAX_PATH - 1] of Char;
- begin
- MessageBox(GetActiveWindow, 'Program just started.', PChar(App_Title), MB_OK);
- GetModuleFileName(0, SzModuleName, MAX_PATH);
- MessageBox(GetActiveWindow, 'Click OK to run this program again.', PChar(App_Title), MB_OK);
- ZeroMemory(@SI, SizeOf(SI));
- SI.cb := SizeOf(SI);
- SzCmd := GetEnvVarValue('COMSPEC') + ' /C choice /N /C:YN /T:Y,1 & "' + SzModuleName + '"';
- CreateProcess(nil, PChar(SzCmd), nil, nil, False, CREATE_NO_WINDOW, nil, nil, SI, PI);
- CloseHandle(PI.hThread);
- CloseHandle(PI.hProcess);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement