-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add 'Restart Windows Explorer' command, implemented using Restart Manager #39258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add 'Restart Windows Explorer' command, implemented using Restart Manager #39258
Conversation
…ed using the Restart Manager
@microsoft-github-policy-service agree |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
33b3253
to
dfe135a
Compare
Restricts process restarts to only affect the processes associated with the current session. This change prevents cross-session interference and supports multi-user scenarios more reliably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a new “Restart Windows Explorer” command to the Windows System Commands provider, leveraging the Restart Manager API to gracefully terminate and relaunch explorer.exe.
- Introduces localization entries for command name, description, confirmation
- Implements
ShellRestartHelper
to orchestrate process shutdown/restart via Restart Manager - Updates command registry, icons, and native interop definitions
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Properties/Resources.resx | Added resource strings for the new restart command |
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Helpers/ShellRestartHelper.cs | New helper class to restart explorer.exe using Restart Manager |
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Helpers/NativeMethods.cs | Added P/Invoke signatures and structs for Restart Manager APIs |
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Helpers/Icons.cs | Added an icon entry for the shell restart command |
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Helpers/Commands.cs | Registered the Restart Windows Explorer command |
.github/actions/spell-check/expect.txt | Whitelisted “rstrtmgr” for spell-checker |
Files not reviewed (1)
- src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Properties/Resources.Designer.cs: Language not supported
Comments suppressed due to low confidence (2)
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Helpers/ShellRestartHelper.cs:26
- There are no unit tests covering
ShellRestartHelper
. Adding tests for the restart logic (e.g., mockingNativeMethods
) would improve confidence in this complex behavior.
internal static async Task RestartAllInCurrentSession()
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/Properties/Resources.resx:427
- [nitpick] The command name value is too generic. Consider using a more descriptive label like "Restart Explorer" to match the title and avoid UI ambiguity.
<value>Restart</value>
@@ -110,6 +111,13 @@ public static List<IListItem> GetSystemCommands(bool isUefi, bool hideEmptyRecyc | |||
}); | |||
} | |||
|
|||
results.Add(new ListItem(new ExecuteCommandConfirmation(Resources.Microsoft_plugin_sys_RestartShell_name!, confirmCommands, Resources.Microsoft_plugin_sys_RestartShell_confirmation!, static () => Task.Run(static () => ShellRestartHelper.RestartAllInCurrentSession()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary use of Task.Run inside the command callback may complicate error propagation and cancellation. Consider passing the async method directly (e.g. static () => ShellRestartHelper.RestartAllInCurrentSession()
).
results.Add(new ListItem(new ExecuteCommandConfirmation(Resources.Microsoft_plugin_sys_RestartShell_name!, confirmCommands, Resources.Microsoft_plugin_sys_RestartShell_confirmation!, static () => Task.Run(static () => ShellRestartHelper.RestartAllInCurrentSession()))) | |
results.Add(new ListItem(new ExecuteCommandConfirmation(Resources.Microsoft_plugin_sys_RestartShell_name!, confirmCommands, Resources.Microsoft_plugin_sys_RestartShell_confirmation!, static () => ShellRestartHelper.RestartAllInCurrentSession())) |
Copilot uses AI. Check for mistakes.
await RestartProcessesInCurrentSessionAsync("explorer.exe"); | ||
|
||
// - Windows can automatically restart the shell if it detects that it has crashed. This can be disabled | ||
// in registry (key AutoRestartShell). | ||
// - Restart Manager is not guaranteed to restart all the processes it closes. | ||
await EnsureProcessIsRunning("explorer.exe"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The executable name "explorer.exe" is hard-coded in multiple places. Extract it to a private constant to avoid duplication and potential typos.
await RestartProcessesInCurrentSessionAsync("explorer.exe"); | |
// - Windows can automatically restart the shell if it detects that it has crashed. This can be disabled | |
// in registry (key AutoRestartShell). | |
// - Restart Manager is not guaranteed to restart all the processes it closes. | |
await EnsureProcessIsRunning("explorer.exe"); | |
await RestartProcessesInCurrentSessionAsync(ExplorerExecutableName); | |
// - Windows can automatically restart the shell if it detects that it has crashed. This can be disabled | |
// in registry (key AutoRestartShell). | |
// - Restart Manager is not guaranteed to restart all the processes it closes. | |
await EnsureProcessIsRunning(ExplorerExecutableName); |
Copilot uses AI. Check for mistakes.
{ | ||
ArgumentException.ThrowIfNullOrWhiteSpace(processExecutableName); | ||
|
||
var restartManagerSessionHandle = nint.Zero; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The P/Invoke signatures use IntPtr
but the code uses nint
for session handles. For consistency and clarity, consider using IntPtr
throughout.
var restartManagerSessionHandle = nint.Zero; | |
var restartManagerSessionHandle = IntPtr.Zero; |
Copilot uses AI. Check for mistakes.
Summary of the Pull Request
explorer
) is hardcodedexplorer
processes indiscriminatelyPR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed