I have finally figured out to how to solve what I wanted.
I post this here as it might help someone else in the same situation.
I now install the program with "administrative install mode", but the old software is uninstalled as the logged in user, if that user has previously installed the old software.
[Code]
function PrepareToInstall(var NeedsRestart: Boolean): string;
var
OldAppGuid, SubKeyName: string;
OldAppFound: Boolean;
ResultCode: Integer;
begin
NeedsRestart := false;
result := '';
begin
OldAppGuid := '{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}';
SubKeyName := 'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\' + OldAppGuid;
OldAppFound := RegKeyExists(HKEY_LOCAL_MACHINE, SubKeyName);
if not OldAppFound then
begin
SubKeyName := 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + OldAppGuid;
OldAppFound := RegKeyExists(HKEY_LOCAL_MACHINE, SubKeyName);
end;
if OldAppFound then
begin
ExecAsOriginalUser(ExpandConstant('{sys}\msiexec.exe'), // Filename
'/X ' + OldAppGuid + ' /qb- REBOOT=ReallySuppress', // Params
'', // WorkingDir
SW_SHOW, // ShowCmd
ewWaitUntilTerminated, // Wait
ResultCode); // ResultCode
end;
end;
end;