Skip to content

Preserve existing CMD AutoRun content and clean up on teardown (#1583) - #2007

Open
Hardik K (hardikkaurani) wants to merge 8 commits into
microsoft:mainfrom
hardikkaurani:fix/1583-cmd-autorun-chaining
Open

Hardik K (hardikkaurani) wants to merge 8 commits into
microsoft:mainfrom
hardikkaurani:fix/1583-cmd-autorun-chaining

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Summary

Fixes #1583.

Previously, setupRegistryAutoRun in cmdStartup.ts invoked reg add ... /f with only our batch file call string (if exist "mainBatchFile" call "mainBatchFile"), which completely overwrote any existing user or third-party configurations in HKCU\Software\Microsoft\Command Processor\AutoRun. Additionally, removeCmdStartup deliberately did not clean up the AutoRun registry key, leaving orphaned entries upon extension disable/uninstall.

This change:

  • Chains rather than overwrites: When existing AutoRun configuration is present, appends our startup call using standard CMD & delimiter (${existing} & ${ourCommand}).
  • Ensures idempotency: If our startup call (or its %USERPROFILE% variant) is already present in AutoRun, leaves the configuration untouched without duplicate entries.
  • Surgically removes on teardown: During teardownScripts, parses the AutoRun command chain and removes only our segment, restoring any prior user commands. If our command was the sole entry, deletes the AutoRun registry value to restore pre-installation state.
  • Adds regression tests: Comprehensive unit test suite covering string tokenization with quotes, merge behavior, idempotency, and surgical removal across all placement scenarios (start, middle, end, sole).

Validation

  • npm run compile-tests (0 errors)
  • npm run compile (webpack bundled cleanly)
  • npm run lint (0 lint issues)
  • mocha out/test/features/terminal/shells/cmd/cmdStartup.unit.test.js (22/22 passing)

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…ardown

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 22:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Hardik K (hardikkaurani) commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi Eduardo Villalpando Mello (@edvilme),

Opening this PR to resolve #1583.

It replaces the registry overwrite in setupRegistryAutoRun with non-destructive & command chaining, keeps setup idempotent, and surgically removes only our startup call during teardown (restoring any pre-existing user commands or deleting the key if ours was the only entry).

All pure string transformations are covered by unit tests.

Whenever you have a moment, I'd appreciate your review and feedback. Thank you!

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.

CMD shell startup integration overwrites user's existing HKCU\...\Command Processor\AutoRun registry value

2 participants