Add 'Restart Windows Explorer' command, implemented using Restart Manager
Summary of the Pull Request
- Adds a new "Restart Windows Explorer" command to the "Windows System Commands" provider
- Implemented using Restart Manager to allow restoring previously opened Explorer windows after restart
- This depends on the "Restore previous folder windows at logon" option in File Explorer Options
- An explicit timeout was added for terminating processes, since Restart Manager uses very long timeouts 😴
- The shell process name (
explorer) is hardcoded - The command attempts to terminate all
explorerprocesses indiscriminately - Execution requires confirmation (if enabled in settings)
PR Checklist
- [ ] Closes: #39213
- [ ] Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
- [ ] Tests: Added/updated and all pass
- [ ] Localization: All end user facing strings can be localized
- [ ] Dev docs: Added/updated
- [ ] New binaries: Added on the required places
- [ ] JSON for signing for new binaries
- [ ] WXS for installer for new binaries and localization folder
- [ ] YML for CI pipeline for new test projects
- [ ] YML for signed pipeline
- [ ] Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
@microsoft-github-policy-service agree
@check-spelling-bot Report
:red_circle: Please review
See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.
Unrecognized words (2)
Restarter rstrtmgr
These words are not needed and should be removed
localappdata pswd SHELLEXTENSION SHELLNEWVALUE SHGFIICON SHGFILARGEICONTo accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands
... in a clone of the [email protected]:jiripolasek/PowerToys.git repository
on the feature/39213-restart-explorer-command branch (:information_source: how do I use this?):
curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/67debf50669c7fc76fc8f5d7f996384535a72b77/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/14850381882/attempts/1'
Errors (3)
See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.
| :x: Errors | Count |
|---|---|
| :x: check-file-path | 1 |
| :x: ignored-expect-variant | 2 |
| :warning: no-newline-at-eof | 1 |
See :x: Event descriptions for more information.
If the flagged items are :exploding_head: false positives
If items relate to a ...
-
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txtfile matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^refers to the file's path from the root of the repository, so^README\.md$would exclude README.md (on whichever branch you're using). -
well-formed pattern.
If you can write a pattern that would match it, try adding it to the
patterns.txtfile.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.
@check-spelling-bot Report
:red_circle: Please review
See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.
Unrecognized words (1)
Restarter
These words are not needed and should be removed
iextn localappdata pswd SHELLEXTENSION SHELLNEWVALUE SHGFIICON SHGFILARGEICONTo accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands
... in a clone of the [email protected]:jiripolasek/PowerToys.git repository
on the feature/39213-restart-explorer-command branch (:information_source: how do I use this?):
curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/67debf50669c7fc76fc8f5d7f996384535a72b77/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/14906408003/attempts/1'
Errors (2)
See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.
| :x: Errors | Count |
|---|---|
| :x: ignored-expect-variant | 2 |
| :warning: no-newline-at-eof | 1 |
See :x: Event descriptions for more information.
If the flagged items are :exploding_head: false positives
If items relate to a ...
-
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txtfile matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^refers to the file's path from the root of the repository, so^README\.md$would exclude README.md (on whichever branch you're using). -
well-formed pattern.
If you can write a pattern that would match it, try adding it to the
patterns.txtfile.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.
I think we make the things more complicated. I've went through your PR, you mentined by default if user kill the explore, it will auto restart (unless user disabled this behaviour by registry).
So, how about just kill explore directly? It's simple and straightforward solution.
The only reason to use the Restart Manager is that it can restore previously opened Explorer windows. When we simply kill the process(es), those windows are not restored.
If we omit restoring the previous folder windows after a restart, we can indeed reduce the code to tskill explorer && start explorer. For me, restoring the previous state is a natural feature, as closing all the windows when restarting Explorer is just collateral damage.
The only reason to use the Restart Manager is that it can restore previously opened Explorer windows. When we simply kill the process(es), those windows are not restored.
If we omit restoring the previous folder windows after a restart, we can indeed reduce the code to
tskill explorer && start explorer. For me, restoring the previous state is a natural feature, as closing all the windows when restarting Explorer is just collateral damage.
Ok, agree. Make sense.
But if restart failed, it will use tskill right?
So there are two behaviours base on user's env (restart manager work/not work).
I think this is so wired for user. Some one will notice they can successfully restore the window but another one will not.
I think it's better to use restart manager but remove the kill/start code path. If it failed, do nothing and show a toast to user.
Any insight?
The only reason to use the Restart Manager is that it can restore previously opened Explorer windows. When we simply kill the process(es), those windows are not restored. If we omit restoring the previous folder windows after a restart, we can indeed reduce the code to
tskill explorer && start explorer. For me, restoring the previous state is a natural feature, as closing all the windows when restarting Explorer is just collateral damage.Ok, agree. Make sense.
But if restart failed, it will use tskill right?
So there are two behaviours base on user's env (restart manager work/not work).
I think this is so wired for user. Some one will notice they can successfully restore the window but another one will not.
I think it's better to use restart manager but remove the kill/start code path. If it failed, do nothing and show a toast to user.
Any insight?
Or we can split this command to 2 command. One is restart another one is kill.
Or add a setting to control the kill behaviour. Restore or not restore.
The only reason to use the Restart Manager is that it can restore previously opened Explorer windows. When we simply kill the process(es), those windows are not restored. If we omit restoring the previous folder windows after a restart, we can indeed reduce the code to
tskill explorer && start explorer. For me, restoring the previous state is a natural feature, as closing all the windows when restarting Explorer is just collateral damage.Ok, agree. Make sense.
But if restart failed, it will use tskill right?
So there are two behaviours base on user's env (restart manager work/not work).
I think this is so wired for user. Some one will notice they can successfully restore the window but another one will not.
I think it's better to use restart manager but remove the kill/start code path. If it failed, do nothing and show a toast to user.
Any insight?
I think we should silently fall back to killing the processes.
As a user, I want to restart Windows Explorer. I don't care how it happens. If I get a toast saying it can't be done, the next thing I'll to do is kill it by another means.
If we care about maintaining 100% consistent behavior, then we should ditch Restart Manager and go with the kill-and-start approach. Using Restart Manager only gives Windows Explorer the option to restore previous folders, but we can’t guarantee that outcome since we don’t control it. In fact, the user can prevent Explorer from restoring folders via File Explorer Options.
Or we can split this command to 2 command. One is restart another one is kill. Or add a setting to control the kill behaviour. Restore or not restore.
I can imagine an option formulated as "Attempt to restore previous folder windows after Windows Explorer restarts," which conveys that we will try, but might not succeed.
I was looking into better error handling and got an idea to replace Restart Manager entirely. It's just rough prototype, but for me it makes more sense: https://github.com/jiripolasek/PowerToys/commit/c374af46b89ca2250a04f5a92122eece01dbfda3
Any thoughts?
I was looking into better error handling and got an idea to replace Restart Manager entirely. It's just rough prototype, but for me it makes more sense: jiripolasek@c374af4
Any thoughts?
oh...
I guess if we send the end message to process, they may show a dialog to user to make them decide exit or save (same as shutdown the computer)?
Actually, I see in the task manager Windows Explorer have a special item "Restart"
I don't know the gap between restart manager and this ability. If we can use this ability I think it's the best choice (to be honest, I don't know anything about it).
Summarize my idea:
I think it should have a stable functionality. Both restart manager and tkill is acceptable for me. But mix it I think it's wired...
or anyone have any idea?
I don't know the gap between restart manager and this ability. If we can use this ability I think it's the best choice (to be honest, I don't know anything about it).
I've researched this a little bit before. Task Manager's "Restart" just kills the process and starts it again.
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
Hello @moooyo, how would you like to follow up with this?
I'd suggest we go with kill-and-start as we can both agree on that solution.
I don't think we should use only Restart Manager as the user experience is not good when Explorer is quirky and won't shutdown upon request from RM (and unfortunately that is not uncommon).
Hello @moooyo, how would you like to follow up with this?
I'd suggest we go with kill-and-start as we can both agree on that solution.
I don't think we should use only Restart Manager as the user experience is not good when Explorer is quirky and won't shutdown upon request from RM (and unfortunately that is not uncommon).
Agree.
And there is still one thing need to address. Could you please try to use LibraryImport instead of DllImport?
If any question or any problem, let me know I'm happy to help .
Without the Restart Manager, there’s no need for those native methods, so I’ll remove them.
@check-spelling-bot Report
:red_circle: Please review
See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.
Unrecognized words (1)
tskill
These words are not needed and should be removed
iwr ZhiweiSome files were automatically ignored :see_no_evil:
These sample patterns would exclude them:
^src/common/CalculatorEngineCommon/exprtk\.hpp$
You should consider adding them to:
.github/actions/spell-check/excludes.txt
File matching is via Perl regular expressions.
To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.
To accept these unrecognized words as correct, update file exclusions, and remove the previously acknowledged and now absent words, you could run the following commands
... in a clone of the [email protected]:jiripolasek/PowerToys.git repository
on the feature/39213-restart-explorer-command branch (:information_source: how do I use this?):
curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/c635c2f3f714eec2fcf27b643a1919b9a811ef2e/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/15670889702/attempts/1' &&
git commit -m 'Update check-spelling metadata'
Pattern suggestions :scissors: (1)
You could add these patterns to .github/actions/spell-check/patterns.txt:
# Automatically suggested patterns
# hit-count: 1 file-count: 1
# curl arguments
\b(?:\\n|)curl(?:\.exe|)(?:\s+-[a-zA-Z]{1,2}\b)*(?:\s+-[a-zA-Z]{3,})(?:\s+-[a-zA-Z]+)*
Alternatively, if a pattern suggestion doesn't make sense for this project, add a #
to the beginning of the line in the candidates file with the pattern to stop suggesting it.
Warnings and Notices :warning: (2)
See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.
| :warning: Warnings and Notices | Count |
|---|---|
| :information_source: candidate-pattern | 1 |
| :warning: large-file | 1 |
See :warning: Event descriptions for more information.
If the flagged items are :exploding_head: false positives
If items relate to a ...
-
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txtfile matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^refers to the file's path from the root of the repository, so^README\.md$would exclude README.md (on whichever branch you're using). -
well-formed pattern.
If you can write a pattern that would match it, try adding it to the
patterns.txtfile.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
Could you please merge main branch into this PR? Seems our pipeline has broken.@jiripolasek
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
Thanks for your contribution!
Thank you for your time and patience @moooyo!