Repository: microsoft/terminal (language: cpp)

Issue:
When default profile is set to Command Prompt, "Open in Windows Terminal" uses cmd.exe in current folder
### Windows Terminal version

1.11.3471.0

### Windows build number

10.0.22526.1000

### Other Software

_No response_

### Steps to reproduce

1. Ensure that cmd.exe from another version of Windows is in the current folder
2. Right-click a black space in Explorer and then click Open in Windows Terminal

### Expected Behavior

Ideally, the system's command prompt should be used as opposed to the one in the current 

### Actual Behavior

The command prompt in the folder is used as opposed to the one from the system

https://user-images.githubusercontent.com/81916167/148704076-bc05a3e8-f018-47e7-bab8-38fceacecd5b.mp4





Discussion / hints:
\<idea for later>:

We look for profiles that have the default command prompt guid, and the commandline set to `cmd.exe`. If we find that, we should replace that with the full path to the system32 `cmd.exe`. We'll discuss Monday
From discussion: We should also do this with Windows Powershell.

Fix patch:
diff --git a/src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp b/src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp
index 2c5138f6db5..6675901de4d 100644
--- a/src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp
+++ b/src/cascadia/LocalTests_SettingsModel/ProfileTests.cpp
@@ -40,6 +40,8 @@ namespace SettingsModelLocalTests
         TEST_METHOD(LayerProfilesOnArray);
         TEST_METHOD(DuplicateProfileTest);
         TEST_METHOD(TestGenGuidsForProfiles);
+
+        TEST_METHOD(TestCorrectOldDefaultShellPaths);
     };
 
     void ProfileTests::ProfileGeneratesGuid()
@@ -347,4 +349,59 @@ namespace SettingsModelLocalTests
 
         VERIFY_ARE_NOT_EQUAL(settings->AllProfiles().GetAt(0).Guid(), settings->AllProfiles().GetAt(1).Guid());
     }
+
+    void ProfileTests::TestCorrectOldDefaultShellPaths()
+    {
+        static constexpr std::string_view inboxProfiles{ R"({
+            "profiles": [
+                {
+                    "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
+                    "name": "Windows PowerShell",
+                    "commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
+                },
+                {
+                    "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
+                    "name": "Command Prompt",
+                    "commandline": "%SystemRoot%\\System32\\cmd.exe",
+                }
+            ]
+        })" };
+        static constexpr std::string_view userProfiles{ R"({
+            "profiles": [
+                {
+                    "name" : "powershell 1",
+                    "commandline": "powershell.exe",
+                    "guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}"
+                },
+                {
+                    "name" : "powershell 2",
+                    "commandline": "powershell.exe",
+                    "guid" : "{61c54bbd-0000-5271-96e7-009a87ff44bf}"
+                },
+                {
+                    "name" : "cmd 1",
+                    "commandline": "cmd.exe",
+                    "guid" : "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}"
+                },
+                {
+                    "name" : "cmd 2",
+                    "commandline": "cmd.exe",
+                    "guid" : "{0caa0dad-0000-5f56-a8ff-afceeeaa6101}"
+                }
+            ]
+        })" };
+
+        const auto settings = winrt::make_self<implementation::CascadiaSettings>(userProfiles, inboxProfiles);
+        const auto allProfiles = settings->AllProfiles();
+        VERIFY_ARE_EQUAL(4u, allProfiles.Size());
+        VERIFY_ARE_EQUAL(L"powershell 1", allProfiles.GetAt(0).Name());
+        VERIFY_ARE_EQUAL(L"powershell 2", allProfiles.GetAt(1).Name());
+        VERIFY_ARE_EQUAL(L"cmd 1", allProfiles.GetAt(2).Name());
+        VERIFY_ARE_EQUAL(L"cmd 2", allProfiles.GetAt(3).Name());
+
+        VERIFY_ARE_EQUAL(L"%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", allProfiles.GetAt(0).Commandline());
+        VERIFY_ARE_EQUAL(L"powershell.exe", allProfiles.GetAt(1).Commandline());
+        VERIFY_ARE_EQUAL(L"%SystemRoot%\\System32\\cmd.exe", allProfiles.GetAt(2).Commandline());
+        VERIFY_ARE_EQUAL(L"cmd.exe", allProfiles.GetAt(3).Commandline());
+    }
 }
diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
index 96ecaa9ac51..4ab872d0e1a 100644
--- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
+++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
@@ -403,6 +403,7 @@ winrt::com_ptr<Profile> CascadiaSettings::_createNewProfile(const std::wstring_v
 // - <none>
 void CascadiaSettings::_validateSettings()
 {
+    _validateCorrectDefaultShellPaths();
     _validateAllSchemesExist();
     _validateMediaResources();
     _validateKeybindings();
diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.h b/src/cascadia/TerminalSettingsModel/CascadiaSettings.h
index f74eb90d1ec..716ccf64d87 100644
--- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.h
+++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.h
@@ -155,6 +155,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
         void _validateMediaResources();
         void _validateKeybindings() const;
         void _validateColorSchemesInCommands() const;
+        void _validateCorrectDefaultShellPaths() const;
         bool _hasInvalidColorScheme(const Model::Command& command) const;
 
         // user settings
diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp
index 9f4a4a1be81..87a7ffdca8d 100644
--- a/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp
+++ b/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp
@@ -977,3 +977,20 @@ void CascadiaSettings::_resolveDefaultProfile() const
     // Use the first profile as the new default.
     GlobalSettings().DefaultProfile(_allProfiles.GetAt(0).Guid());
 }
+
+void CascadiaSettings::_validateCorrectDefaultShellPaths() const
+{
+    for (auto profile : _allProfiles)
+    {
+        if (profile.Guid() == DEFAULT_COMMAND_PROMPT_GUID &&
+            profile.Commandline() == L"cmd.exe")
+        {
+            profile.ClearCommandline();
+        }
+        else if (profile.Guid() == DEFAULT_WINDOWS_POWERSHELL_GUID &&
+                 profile.Commandline() == L"powershell.exe")
+        {
+            profile.ClearCommandline();
+        }
+    }
+}


Test patch: