Skip to content

Undo Internals

Taiizor edited this page Jun 5, 2026 · 4 revisions

Undo Internals

Despite the "rollback" name, the shipped Sucrose.Undo.exe is effectively Sucrose's uninstaller / full-removal tool. It is the process Windows runs when you remove Sucrose from Apps & Features, and it is responsible for terminating every Sucrose process, deleting the install and (optionally) the user-data folders, removing shortcuts and the registry uninstall key, restoring hidden desktop icons, and finally deleting itself with a self-cleaning batch file. This page documents that removal flow for developers and administrators. For the user-facing steps, see Uninstalling Sucrose.

Contents

Role and entry point

Sucrose.Undo.exe is a WPF process registered as the uninstaller for Sucrose. Unlike most Sucrose apps, it does not single-instance-gate through Instance.Basic, and it does not route its own crashes through the Watchdog (see Exception handling).

Its behavior depends on whether it is launched with arguments:

  • No arguments — plays SystemSounds.Asterisk and shows a localized confirmation dialog (the interactive uninstall).
  • With any argument (e.g. -s) — the confirmation dialog is skipped. Note: in the current code the no-argument (interactive) path is the only one that triggers removal; when an argument is supplied the dialog is skipped but the internal result stays Cancel, so the removal block is not executed and nothing is removed. The registry uninstall entry does store a QuietUninstallString of the form "<Undo.exe path>" -s (written by the Bundle/installer, intended for choco uninstall, scoop uninstall, winget, etc.).

The Yes / No / Cancel dialog

When launched interactively, Undo shows a localized Yes / No / Cancel dialog (resource keys Undo.QuestionTitle, Undo.QuestionMessage, Undo.QuestionDescription). The choice controls whether user data is kept:

Choice Removes app? Removes user data?
Yes Yes Yes — also deletes UninstallDataPath = %AppData%\Sucrose
No Yes No — keeps %AppData%\Sucrose
Cancel No (abort)

The Sucrose Undo Yes/No/Cancel uninstall confirmation dialog

Removal sequence

On Yes or No, Undo performs the following (Cancel aborts before any of it):

  1. Terminate all Sucrose processes — kills every process whose name contains Sucrose, in 2 passes spaced 1 second apart (Delay = 1000), so freshly-spawned helpers (Commandog, etc.) are also caught.
  2. Restore the desktop — restores desktop-icon visibility and calls RefreshDesktop() (Sucrose can hide desktop icons while a wallpaper runs).
  3. Delete the install folder — removes UninstallPath = %LocalAppData%\Sucrose, preserving the currently running Undo and Runtime folders (those are removed later by the batch file).
  4. Optionally delete user data — on Yes, also deletes UninstallDataPath = %AppData%\Sucrose.
  5. Remove shortcuts — deletes the Desktop and Start-Menu <AppLongName>.lnk shortcuts.
  6. Remove the registry uninstall key — deletes the HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\Sucrose subkey (see below).
  7. Self-delete — generates and runs a batch file in %TEMP% that finishes the job after Undo exits.

The self-deleting batch

The install folder cannot fully delete the running Undo.exe and the private Sucrose.Runtime while they are in use, so Undo writes a one-shot batch file to the temp folder and launches it:

%TEMP%\del_<guid>.bat

The batch:

taskkill /PID <undo pid> /T /F
timeout /t 3
rd /s /q "<Sucrose.Undo folder = %LocalAppData%\Sucrose\Sucrose.Undo>"
rd /s /q "<Sucrose.Runtime folder = %LocalAppData%\Sucrose\Sucrose.Runtime>"
rd /s /q "<install root = %LocalAppData%\Sucrose>"
del "%~f0"

In words: taskkill the Undo process itself, wait 3 seconds for handles to release, recursively delete the remaining install / runtime / uninstall paths, then delete the batch file. This is how the last on-disk traces are removed after the WPF process is already gone.

flowchart TD
    Start["Sucrose.Undo.exe"] --> Dlg{"Yes / No / Cancel"}
    Dlg -->|Cancel| Abort["abort, no changes"]
    Dlg -->|Yes or No| Kill["kill all Sucrose processes<br/>2 passes, 1s apart"]
    Kill --> Desk["restore desktop icons<br/>+ RefreshDesktop()"]
    Desk --> DelInstall["delete %LocalAppData%/Sucrose<br/>keep Undo + Runtime folders"]
    DelInstall --> Data{"choice == Yes?"}
    Data -->|yes| DelData["also delete %AppData%/Sucrose"]
    Data -->|no| KeepData["keep user data"]
    DelData --> Short["remove Desktop + Start-Menu shortcuts"]
    KeepData --> Short
    Short --> Reg["delete HKCU Uninstall key (Sucrose)"]
    Reg --> Bat["spawn %TEMP%/del_&lt;guid&gt;.bat"]
    Bat --> Self["batch: taskkill Undo,<br/>delete install/runtime/uninstall, self-delete"]
Loading

Registry and the uninstall entry

Sucrose installs per-user (no admin), so its uninstall entry lives under the current-user hive:

HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\Sucrose

This is the entry that makes Sucrose appear in Apps & Features; its QuietUninstallString uses the -s switch for silent removal. Undo deletes this key as part of the removal sequence. The key is created by the installer, not by Undo — see Bundle / Installer Internals.

Exception handling

Undo handles its own unhandled exceptions with a plain WPF MessageBox — it deliberately does not route through the Crash Reporting Watchdog pipeline. This is intentional: by the time Undo runs, it may already have terminated the Watchdog and Commandog processes that the crash pipeline depends on, so a self-contained dialog is the only reliable feedback.

See also

Home

Getting Started

Wallpaper Types

Using Sucrose

Settings Reference

Creating Wallpapers

Engine Reference

Automation & Command Line

Architecture & Internals

Data, Files & Diagnostics

Building & Contributing

Help & Support

Clone this wiki locally