Skip to content
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

Set the Windows Terminal as the default terminal #1093

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

d35ha
Copy link
Member

@d35ha d35ha commented Jun 14, 2024

Closes #971.
Closes #973.

@d35ha d35ha requested a review from Ana06 June 14, 2024 11:46
@d35ha d35ha self-assigned this Jun 14, 2024
@d35ha d35ha added this to the FLARE-VM 2024 Q2 - P1 milestone Jun 14, 2024
@d35ha d35ha added the 💎 enhancement It is working, but it could be better label Jun 14, 2024
@Ana06
Copy link
Member

Ana06 commented Jun 14, 2024

I am not sure this works as proposed in #971. @d35ha can you provide more details on how this works and how it looks like (maybe adding a screenshot)?

@d35ha
Copy link
Member Author

d35ha commented Jun 14, 2024

@Ana06
I've created a console app, here is how its execution looks before and after setting these registry values:

before

after

Also, running cmd or powershell (from start menu or by double-clicking) opens it in Windows Terminal.

@d35ha
Copy link
Member Author

d35ha commented Jun 14, 2024

@Ana06
#973 is also addressed in this PR.

@Ana06
Copy link
Member

Ana06 commented Jun 18, 2024

@d35ha is proposing using the windows terminal to open the shortcuts in the Tools directory, is this PR achieving this?

@d35ha
Copy link
Member Author

d35ha commented Jun 24, 2024

@Ana06
Any application that requires a console would be assigned the Windows terminal console instead of the the old conhost.exe (that is including the shortcuts under the Tools directory).

@@ -54,6 +55,12 @@ try {
$label = "Open Terminal here"
$icon = "$executablePath"
VM-Add-To-Right-Click-Menu -menuKey $toolName -menuLabel $label -command $command -menuIcon $icon -type "directory" -background

# Set windows terminal as the default terminal (effective only when OS Build >= 19045.3031)
Copy link
Member

Choose a reason for hiding this comment

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

I am using 10.0.19045.0 (downloaded from the recommended link in FLARE-VM), so this approach does not work

@Ana06 Ana06 requested a review from emtuls July 15, 2024 14:32
@Ana06 Ana06 removed this from the FLARE-VM 2024 Q3 - P1 milestone Jul 16, 2024
@emtuls
Copy link
Member

emtuls commented Oct 24, 2024

I looked into this a little bit more.

I wanted to try and find a way to have any "console app" shortcut open with Windows Terminal (if it exists) or cmd.exe if not, but the way to make that happen would likely require an external script to launch the correct one. I tried creating a singular command that can be done within a shortcut target cmd, but it ended up being too long.

An alternative would be that we force Windows Terminal to be installed, but I believe this would require modification of our install script so that it is always installed if I'm not mistaken?

Let me know if that's the preferred route and I can work on that.

@emtuls
Copy link
Member

emtuls commented Oct 24, 2024

Assuming we go the route of a forced Windows Terminal install...I got something mostly working for Command Prompt, but it seems like Powershell is going to be a lot more of an issue due to a long standing bug with Windows Terminal and how it interprets semicolons: microsoft/terminal#13264

This makes it very difficult, if not impossible to do our powershell shortcuts. I was able to make one work, but it would require removing the Write-Host portion (echoing the command we write into the console).

For reference for powershell, I modified powersploit to use this as arguments for VM-Install-Shortcut:
$powershellCommand = 'Get-Command -Module (Import-Module .\Recon\Recon.psd1)'

This still seems to work as expected, just a re-write of the original command we used so it doesn't use a semicolon:
Import-Module .\Recon\Recon.psd1 ; Get-Command -Module Recon

And I modified VM-Install-Shortcut to use the following for the else statement (for when it is powershell):

$executableCmd = Get-ChildItem "C:\Tools\Windows Terminal\terminal-*" -Filter wt.exe -Recurse | Select-Object -ExpandProperty FullName -First 1
VM-Assert-Path $executableCmd
$executableArgs = "-p `"Powershell`" -d `"$executableDir`" `"powershell.exe -ExecutionPolicy Bypass -NoExit -Command ""$arguments""`""

This generated the following shortcut target:
"C:\Tools\Windows Terminal\terminal-1.19.10573.0\wt.exe" -p "PowerShell" "powershell.exe -NoExit -Command ""Get-Command -Module (Import-Module .\Recon\Recon.psd1)""

For reference for Command Prompt (console apps) that seems to just 'work', I tested with exiftool and only had to modify VM-Install-Shortcut:

if ($consoleApp) {
    $executableCmd = Get-ChildItem "C:\Tools\Windows Terminal\terminal-*" -Filter wt.exe -Recurse | Select-Object -ExpandProperty FullName -First 1
    VM-Assert-Path $executableCmd
    # Set the starting directory, print the command, and execute it within wt.exe
    $executableArgs = "-p `"Command Prompt`" -d `"$executableDir`" `"cmd.exe /k echo $executablePath $arguments && $executablePath $arguments`""

@Ana06
Copy link
Member

Ana06 commented Nov 4, 2024

Thanks for the research @emtuls! I suggest we merge this PR as it is, as it seems it is not easy to support it in our Windows version.

Copy link
Member

@Ana06 Ana06 left a comment

Choose a reason for hiding this comment

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

I think it is nice that previous versions benefit from the improvement even if it does not work in older version. I have tested it in 10.0.19045.0 and it does not seem to introduce any issues (it also does modify the behavior).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 enhancement It is working, but it could be better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change new tabs default in Windows terminal to CMD Make Windows Terminal the default to run console apps
3 participants