Skip to content

Never delete an account during a simulation - #31

Merged
rodchristiansen merged 2 commits into
mainfrom
fix/simulate-never-deletes
Oct 6, 2026
Merged

rodchristiansen merged 2 commits into
mainfrom
fix/simulate-never-deletes

Conversation

@rodchristiansen

@rodchristiansen rodchristiansen commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A simulation is meant to change nothing, but it did two things:

  • manageusers --simulate deleted local accounts that have no profile. RemoveOrphanedUsers deleted the account directly and never checked simulate mode, so a dry run removed real accounts. Every other deletion path already checked the mode.

Fix

  • The orphan path audits ORPHAN_USER_REMOVE_SIMULATED and leaves the account in place.
  • Backstop: account deletion refuses to run during a simulation, whichever path reaches it.
  • UpdateHiddenUsers no longer writes Winlogon\SpecialAccounts\UserList during a simulation. It logs SIMULATE: would hide <account> from the sign-in screen instead.

Tests

New tests/ManageUsers.Tests (xUnit). It uses two small test seams: an injectable command runner and a log constructor that writes to a temp folder.

  • Simulation, orphan path: no command runs, nothing is recorded as removed, and the audit has the simulated entries.
  • Simulation, ordinary account path: no command runs.
  • Live control: the orphan path runs net user "<name>" /delete.
  • Hidden users, tested against a key under HKCU: a simulation creates nothing and logs what it would hide; a live run writes the value.

dotnet test tests/ManageUsers.Tests: 5 passed.

#29 and its stacked #30 will be rebased onto this.

manageusers --simulate removed local accounts that have no profile: the
orphan path called the account deletion directly and never checked the
mode, so a dry run deleted real accounts. It now audits what it would
remove and leaves them, and the account deletion itself refuses to run
during a simulation, whichever path reaches it.

Adds a test project with regression tests for the orphan path and the
ordinary account path, plus a live-mode control.
A simulation wrote the hidden-accounts list under Winlogon\SpecialAccounts\UserList,
hiding excluded accounts from the sign-in screen. It now logs which accounts it would
hide and writes nothing. Adds a test against a key under HKCU, with a live control.
@rodchristiansen
rodchristiansen merged commit 3580bef into main Oct 6, 2026
1 check passed
@rodchristiansen
rodchristiansen deleted the fix/simulate-never-deletes branch October 6, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant