Add deletion of leftovers
This commit is contained in:
parent
6491035d16
commit
f550ab90ee
|
@ -644,6 +644,115 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function IsAdmin: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure DeleteSandboxiePlusLeftovers;
|
||||
var
|
||||
RegKeys: array[0..2] of string;
|
||||
I, J: Integer;
|
||||
RegValueName: string;
|
||||
FilePatterns: array[0..9] of string;
|
||||
DirPattern: string;
|
||||
begin
|
||||
// Define registry keys to clean up.
|
||||
RegKeys[0] := 'Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache';
|
||||
RegKeys[1] := 'Software\Microsoft\Windows\CurrentVersion\UFH\SHC';
|
||||
RegKeys[2] := 'Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store';
|
||||
|
||||
// Iterate over the registry paths.
|
||||
for I := 0 to High(RegKeys) do
|
||||
begin
|
||||
// Check if the registry key exists.
|
||||
if RegKeyExists(HKEY_CURRENT_USER, RegKeys[I]) then
|
||||
begin
|
||||
// Try to delete values that may contain "Sandboxie-Plus".
|
||||
J := 0;
|
||||
while True do
|
||||
begin
|
||||
// Attempt to get a value name at index J
|
||||
// Note: RegEnumValue doesn't exist in Inno Setup, so we manually try to access values.
|
||||
// You may want to manually add known value names or add a pattern match.
|
||||
|
||||
// Attempt to get the value data for the current index (J) under the key.
|
||||
if RegQueryStringValue(HKEY_CURRENT_USER, RegKeys[I], 'ValueName' + IntToStr(J), RegValueName) then
|
||||
begin
|
||||
// If the value contains "Sandboxie-Plus", delete it.
|
||||
if Pos('Sandboxie-Plus', RegValueName) > 0 then
|
||||
begin
|
||||
if RegDeleteValue(HKEY_CURRENT_USER, RegKeys[I], 'ValueName' + IntToStr(J)) then
|
||||
Log('Deleted registry value: ValueName' + IntToStr(J) + ' under ' + RegKeys[I])
|
||||
else
|
||||
Log('Failed to delete registry value: ValueName' + IntToStr(J) + ' under ' + RegKeys[I]);
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
// If no value is found at this index, break out of the loop.
|
||||
Break;
|
||||
end;
|
||||
Inc(J); // Increment to check the next value
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Log('Registry key does not exist: ' + RegKeys[I]);
|
||||
end;
|
||||
end;
|
||||
|
||||
// Attempt to delete Prefetch files only if the installer is running with admin privileges.
|
||||
if IsAdmin then
|
||||
begin
|
||||
// Define file patterns to clean up.
|
||||
FilePatterns[0] := '{win}\Prefetch\KMDUTIL.EXE-*.pf';
|
||||
FilePatterns[1] := '{win}\Prefetch\SANDBOXIE-PLUS-*.pf';
|
||||
FilePatterns[2] := '{win}\Prefetch\SANDBOXIEDCOMLAUNCH.EXE-*.pf';
|
||||
FilePatterns[3] := '{win}\Prefetch\SANDBOXIERPCSS.EXE-*.pf';
|
||||
FilePatterns[4] := '{win}\Prefetch\SANDMAN.EXE-*.pf';
|
||||
FilePatterns[5] := '{win}\Prefetch\SBIECTRL.EXE-*.pf';
|
||||
FilePatterns[6] := '{win}\Prefetch\SBIESVC.EXE-*.pf';
|
||||
FilePatterns[7] := '{win}\Prefetch\START.EXE-*.pf';
|
||||
FilePatterns[8] := '{win}\Prefetch\UPDUTIL.EXE-*.pf';
|
||||
FilePatterns[9] := '{localappdata}\Temp\qtsingleapp-sandma-*';
|
||||
|
||||
// Attempt to delete files matching the patterns above (if admin rights are available).
|
||||
for I := 0 to High(FilePatterns) do
|
||||
begin
|
||||
if FileExists(ExpandConstant(FilePatterns[I])) then
|
||||
begin
|
||||
if DeleteFile(ExpandConstant(FilePatterns[I])) then
|
||||
begin
|
||||
// Log successful deletion of the file.
|
||||
Log('Deleted file: ' + ExpandConstant(FilePatterns[I]));
|
||||
end
|
||||
else
|
||||
begin
|
||||
// Log that the file could not be deleted due to permission issues.
|
||||
Log('Failed to delete (permission denied): ' + ExpandConstant(FilePatterns[I]));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
// Log that Prefetch file deletion was skipped due to lack of admin privileges.
|
||||
Log('Skipped Prefetch file deletion due to lack of admin privileges.');
|
||||
end;
|
||||
|
||||
// Define the single directory to clean up.
|
||||
DirPattern := '{localappdata}\Temp\sandboxie-updater';
|
||||
|
||||
// Delete the directory if it exists.
|
||||
if DirExists(ExpandConstant(DirPattern)) then
|
||||
begin
|
||||
if DelTree(ExpandConstant(DirPattern), True, True, True) then
|
||||
Log('Deleted directory: ' + ExpandConstant(DirPattern))
|
||||
else
|
||||
Log('Failed to delete directory: ' + ExpandConstant(DirPattern));
|
||||
end;
|
||||
end;
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Uninstallation Events
|
||||
|
@ -676,4 +785,7 @@ begin
|
|||
// Remove shell integration.
|
||||
ShellUninstall();
|
||||
|
||||
// Call the cleanup procedure.
|
||||
DeleteSandboxiePlusLeftovers;
|
||||
|
||||
end;
|
||||
|
|
Loading…
Reference in New Issue