Change "Open windows from a previous session" behavior to not automatically run .bat files without confirmation #17719

Open
opened 2026-01-31 05:51:21 +00:00 by claunia · 3 comments
Owner

Originally created by @rjk on GitHub (Jun 15, 2022).

Originally assigned to: @lhecker on GitHub.

Description of the new feature/enhancement

Currently if you have the setting "Open windows from a previous session" on it will re-run .bat files that were executed in a previous session. e.g.

  • you double-click a .bat file to run it
  • you close the Terminal window
  • you later open Terminal e.g. from Start menu
  • Terminal will re-run that .bat file.

I think this is very surprising and potentially destructive behavior. Users would not expect that to happen or consider the potential disasters when enabling that setting.

I initially raised this as a bug in https://github.com/microsoft/terminal/issues/13151 which was closed as By Design, which is fine. This new issue is a suggestion to change the design.

Proposed technical implementation details

I think Terminal should do something else, e.g. one of these:

  • be more clever about what things it runs without user confirmation (e.g. perhaps it asks for user confirmation when running .bat and .cmd files on open, since they can be destructive. Or it simply never runs those types of files). I don't know enough about shells to know if this is easy/hard/impossible/annoying
  • give a big warning about this behavior on the setting page.
  • have two settings: one to persist tabs & working directories from previous sessions, one to persist potentially-destructive actions.

I don't think the setting page warning is sufficient, since many users will be blissfully unaware of all this. They might want tabs open from previous sessions, use that for months, and then just one time they use a .bat file for something. (Here, run this cleanup_files.bat but be careful not to run it with any unsaved changes). They open Terminal sometime later and BOOM the nasty .bat file has unexpectedly run. They lose their work, become sad, and end up hating Terminal forever :'(

Originally created by @rjk on GitHub (Jun 15, 2022). Originally assigned to: @lhecker on GitHub. # Description of the new feature/enhancement Currently if you have the setting "Open windows from a previous session" on it will re-run .bat files that were executed in a previous session. e.g. * you double-click a .bat file to run it * you close the Terminal window * you later open Terminal e.g. from Start menu * Terminal will re-run that .bat file. I think this is very surprising and potentially destructive behavior. Users would not expect that to happen or consider the potential disasters when enabling that setting. I initially raised this as a bug in https://github.com/microsoft/terminal/issues/13151 which was closed as By Design, which is fine. This new issue is a suggestion to change the design. # Proposed technical implementation details I think Terminal should do something else, e.g. one of these: * be more clever about what things it runs without user confirmation (e.g. perhaps it asks for user confirmation when running .bat and .cmd files on open, since they can be destructive. Or it simply never runs those types of files). I don't know enough about shells to know if this is easy/hard/impossible/annoying * give a big warning about this behavior on the setting page. * have two settings: one to persist tabs & working directories from previous sessions, one to persist potentially-destructive actions. I don't think the setting page warning is sufficient, since many users will be blissfully unaware of all this. They might want tabs open from previous sessions, use that for months, and then just one time they use a .bat file for something. (_Here, run this cleanup_files.bat but be careful not to run it with any unsaved changes_). They open Terminal sometime later and BOOM the nasty .bat file has unexpectedly run. They lose their work, become sad, and end up hating Terminal forever :'(
claunia added the Issue-FeatureArea-SettingsProduct-Terminal labels 2026-01-31 05:51:21 +00:00
Author
Owner

@carlos-zamora commented on GitHub (Jul 25, 2022):

Sync meeting notes:

image

Add an option like...
"Open windows from a previous session including defterm sessions"
vs
"Open windows from a previous session excluding defterm sessions" (this is the one that exists now)

@carlos-zamora commented on GitHub (Jul 25, 2022): Sync meeting notes: <img width="698" alt="image" src="https://user-images.githubusercontent.com/11050425/180873895-6bbff34e-2234-49cc-a06b-a4baeef5ff9f.png"> Add an option like... "Open windows from a previous session including defterm sessions" vs "Open windows from a previous session excluding defterm sessions" (this is the one that exists now)
Author
Owner

@lhecker commented on GitHub (Aug 10, 2022):

I started working on this in https://github.com/microsoft/terminal/compare/dev/lhecker/13151-defterm-persistence but I can't figure out how to properly handle split panes where both children are DefTerm sessions. The way Pane::BuildStartupActions works isn't particularly easy to modify for ad-hoc filtering like that. I'll try to pick this up next week again and finish it with the help of others.

@lhecker commented on GitHub (Aug 10, 2022): I started working on this in https://github.com/microsoft/terminal/compare/dev/lhecker/13151-defterm-persistence but I can't figure out how to properly handle split panes where both children are DefTerm sessions. The way `Pane::BuildStartupActions` works isn't particularly easy to modify for ad-hoc filtering like that. I'll try to pick this up next week again and finish it with the help of others.
Author
Owner

@zadjii-msft commented on GitHub (Aug 11, 2022):

Oh, we may want to cross-reference with #13596 while we're here. Maybe this needs to be two separate sets of settings:

  • When Terminal starts
    • Open default profile
    • Open tabs from previous session, excluding defterm
    • Open tabs from previous session, including defterm
  • When Terminal starts as admin
    • Open default profile
    • Open tabs from previous session (no defterm settings here cause... well, you know, defterm doesn't work for elevated windows)
@zadjii-msft commented on GitHub (Aug 11, 2022): Oh, we may want to cross-reference with #13596 while we're here. Maybe this needs to be two separate sets of settings: * When Terminal starts * Open default profile * Open tabs from previous session, excluding defterm * Open tabs from previous session, including defterm * When Terminal starts as admin * Open default profile * Open tabs from previous session (no defterm settings here cause... well, you know, defterm doesn't work for elevated windows)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17719