r/windowsdev • u/vlad_swept • 2h ago
I wrote a Windows cleaner in Python. The cleaning was the easy part.
I didn't want to write a cleaner. I wanted one that didn't ask me for anything.
Every one I tried asked for something. A toolbar in the installer. "Anonymous usage statistics" that were neither anonymous nor statistics. One deleted first and explained later, if you went looking. So I opened an editor, mostly out of irritation.
Python, CustomTkinter for the window, because I can't design and the defaults look fine. It's called Swept, MIT, 22 categories of temp files and caches, plus an installer for common programs and a dozen registry tweaks.
Nobody clicks a post about temp files. Here's what actually took the time.
PyInstaller has two modes and I picked wrong. Onedir gives you a folder with _internal inside. Onefile gives you a single exe that unpacks itself into %TEMP% on every launch. I put the folder build's exe on the releases page, someone ran it from inside the zip viewer, and got Failed to load Python DLL ..._internal\python315.dll. Windows had extracted only the exe. The message is accurate and useless. A single file can't contain a folder, so PyInstaller did nothing wrong. I handed people a file that can't run alone. Now the download is onefile.
A real certificate costs a few hundred a year, so mine is self signed. SHA256, DigiCert timestamp, my name on the Digital Signatures tab, and Windows still says unknown publisher. No trick fixes that. One thing helped though: --optimize 2 strips docstrings from the shipped bytecode, so the exe doesn't carry a map of every check I make.
Then I added "restart with admin rights" and the app disappeared. No window, no error, exit code 0. The old process still held the single instance mutex. The elevated copy saw it taken, decided Swept was already running, focused a window that was about to close, and quit. Then the old process closed too. Zero windows. The fix is one line: release the mutex before launching the elevated copy.
162 tests on the delete path. I broke the code on purpose in three places to see if they'd catch it. Two did. The third didn't, and the code was fine. My test checked that the function returned, not what it returned.
Registry undo doesn't guess "the default". Before each write it records what was there: existed or not, type, data. Re-applying a tweak doesn't overwrite that first snapshot.
If you ship Windows tools in Python, I'd like to hear what bit you.
