Some small nitpicks:
// Wait until GliderMaintenance is closed
while (GmIsRunning(strProgram) <> 0) do bActive := True; // GliderMaintenance.exe
This is a busy loop that eats up CPU cycles. At least put a small sleep in the loop to yield cycles.
A better option would be to open a handle to the process if it is running, and then wait on the handle to be signaled when the process exits. That way, the wait can sleep the entire time the handle is unsignaled.
// Delete archived previous version
DeleteFile(PChar(strOldProgram)); // GliderMaintenance-old.exe «-------- This fails in Windows 11
What is the error code when that happens? From your latest update, it was probably 2 (
ERROR_FILE_NOT_FOUND). Always check error codes when making system calls!
// Rename current main program to old and after that rename new main version to current name
if RenameFile(strProgram, strOldProgram) // GliderMaintenance.exe -> GliderMaintenance-old.exe
then RenameFile(strNewProgram, strProgram); // GliderMaintenance.new -> GliderMaintenance.exe
You should consider using the Win32
ReplaceFile() function instead, eg:
ReplaceFile(PChar(strProgram), PChar(strNewProgram), PChar(strOldProgram), 0, nil, nil);
// Start new version of GliderMaintenance
ShellExecute(Handle, 'open', PChar(strProgram), nil, nil, 1);
You should be using
CreateProcess() instead.
ShellExecute() is just going to call it anyway, so you can cut out the middle-man. Yes, it is slightly more code to use
CreateProcess(), but it is less overhead to avoid invoking the Shell.