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 Windows Terminal as pinned console #962

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/common.vm/common.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>common.vm</id>
<version>0.0.0.20240321</version>
<version>0.0.0.20240402</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
32 changes: 21 additions & 11 deletions packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ function VM-Install-Shortcut{
# Set the default icon to be the executable's icon
if (-Not $iconLocation) {$iconLocation = $executablePath}

if ($consoleApp -or $powershell) {
if (-not $executableDir) {
$executableDir = Join-Path ${Env:UserProfile} "Desktop"
}
VM-Assert-Path $executableDir
if (-not $executableDir) {
$executableDir = Join-Path ${Env:UserProfile} "Desktop"
}
VM-Assert-Path $executableDir

if ($consoleApp -or $powershell) {
if ($consoleApp) {
$executableCmd = Join-Path ${Env:WinDir} "system32\cmd.exe" -Resolve
# Change to executable dir, print command to execute, and execute command
Expand All @@ -307,19 +307,19 @@ function VM-Install-Shortcut{
if ($runAsAdmin) {
$shortcutArgs.RunAsAdmin = $true
}

Install-ChocolateyShortcut @shortcutArgs

} else {
$shortcutArgs = @{
ShortcutFilePath = $shortcut
TargetPath = $executablePath
Arguments = $arguments
WorkingDirectory = $executableDir
IconLocation = $iconLocation
}
if ($runAsAdmin) {
$shortcutArgs.RunAsAdmin = $true
}

Install-ChocolateyShortcut @shortcutArgs
}
VM-Assert-Path $shortcut
Expand Down Expand Up @@ -707,7 +707,9 @@ function VM-Add-To-Right-Click-Menu {
[ValidateSet("file", "directory")]
[string] $type="file",
[Parameter(Mandatory=$false)]
[string] $extension
[string] $extension,
[Parameter(Mandatory=$false)]
[switch] $background
)
try {
if ($extension) {
Expand All @@ -717,7 +719,10 @@ function VM-Add-To-Right-Click-Menu {
if ($type -eq "file") {
$key = "*"
} else {
$key = "directory"
$key = "Directory"
if ($background) {
$key += "\Background"
}
}
}
$key_path = "HKCR:\$key\shell\$menuKey"
Expand Down Expand Up @@ -755,7 +760,9 @@ function VM-Remove-From-Right-Click-Menu {
[ValidateSet("file", "directory")]
[string] $type="file",
[Parameter(Mandatory=$false)]
[string] $extension
[string] $extension,
[Parameter(Mandatory=$false)]
[switch] $background
)
try {
if ($extension) {
Expand All @@ -765,7 +772,10 @@ function VM-Remove-From-Right-Click-Menu {
if ($type -eq "file") {
$key = "*"
} else {
$key = "directory"
$key = "Directory"
if ($background) {
$key += "\Background"
}
}
}
$key_path = "HKCR:\$key\shell\$menuKey"
Expand Down
2 changes: 1 addition & 1 deletion packages/debloat.vm/debloat.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>debloat.vm</id>
<version>0.0.0.20240321</version>
<version>0.0.0.20240327</version>
<description>Debloat and performance configurations for Windows OS</description>
<authors>Mandiant</authors>
<dependencies>
Expand Down
2 changes: 0 additions & 2 deletions packages/debloat.vm/tools/win10.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@
<registry-item name="Disable Windows Update Automatic Download" path="HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" value="AUOptions" type="DWord" data="2" />
<registry-item name="Disable Windows Update Automatic Restart" path="HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\MusNotification.exe" value="Debugger" type="String" data="cmd.exe" />
<registry-item name="Disable Microsoft Connectivity Test (msftconnecttest.com)" path="HKLM:\SYSTEM\CurrentControlSet\services\NlaSvc\Parameters\Internet" value="EnableActiveProbing" type="DWord" data="0" />
<registry-item name="Enable opening cmd from context menu - Default" path="Registry::HKEY_CLASSES_ROOT\Directory\Background\shell\ctx_cmd" value="(Default)" type="String" data="Cmd Here" />
<registry-item name="Enable opening cmd from context menu - Command" path="Registry::HKEY_CLASSES_ROOT\Directory\Background\shell\ctx_cmd\command" value="(Default)" type="String" data="&quot;cmd.exe&quot; &quot;pushd &quot;%V&quot;&quot;" />
</registry-items>
<path-items>
<!--
Expand Down
2 changes: 1 addition & 1 deletion packages/installer.vm/installer.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>installer.vm</id>
<version>0.0.0.20240321</version>
<version>0.0.0.20240402</version>
<authors>Mandiant</authors>
<description>Generic installer for custom virtual machines.</description>
<dependencies>
Expand Down
12 changes: 0 additions & 12 deletions packages/installer.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ try {
## Configure taskbar with custom Start Layout if it exists.
$customLayout = Join-Path ${Env:VM_COMMON_DIR} "CustomStartLayout.xml"
if (Test-Path $customLayout) {
# Create an Admin Command Prompt shortcut and it to pin to taskbar (analogous to how the Windows Dev VM does this).
$toolName = 'Admin Command Prompt'

$executablePath = Join-Path ${Env:SystemRoot} 'system32\cmd.exe'
$shortcutDir = ${Env:RAW_TOOLS_DIR}
$shortcut = Join-Path $shortcutDir "$toolName.lnk"
$workingDir = Join-Path ${Env:UserProfile} "Desktop"
$arguments = "/k `"cd `"$workingDir`"`""

Install-ChocolateyShortcut -shortcutFilePath $shortcut -targetPath $executablePath -Arguments $arguments -RunAsAdmin
VM-Assert-Path $shortcut

Import-StartLayout -LayoutPath $customLayout -MountPath "C:\"
Stop-Process -Name explorer -Force # This restarts the explorer process so that the new taskbar is displayed.
} else {
Expand Down
29 changes: 26 additions & 3 deletions packages/windows-terminal.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,32 @@ try {
# GitHub ZIP files typically unzip to a single folder that contains the tools.
$dirList = Get-ChildItem $toolDir -Directory
$toolDir = Join-Path $toolDir $dirList[0].Name -Resolve

$workingDir = Join-Path ${Env:UserProfile} "Desktop"
$arguments = "-p `"Command Prompt`" -d `"$workingDir`"" # Working directory doesn't work for admin shortcuts, so use -d flag for it.
$executablePath = Join-Path $toolDir $executableName -Resolve
VM-Install-Shortcut -toolName $toolName -category $category -executablePath $executablePath -runAsAdmin
VM-Install-Shortcut -toolName $toolName -category $category -executablePath $executablePath -arguments $arguments -runAsAdmin

# Create a basic settings.json file so Windows Terminal always opens with elevated privileges
emtuls marked this conversation as resolved.
Show resolved Hide resolved
$settingsPath = "${Env:LOCALAPPDATA}\Microsoft\Windows Terminal\settings.json"
$settingsFileDir = Split-Path $settingsPath
New-Item -ItemType Directory -Force -Path $settingsFileDir
$defaultSettings = @"
{
"`$schema": "https://aka.ms/terminal-settings-schema-v1.1",
"profiles": {
"defaults": {
"elevate": true
}
}
}
"@
$defaultSettings | Out-File $settingsPath -Encoding Utf8

# Add right click for Windows Terminal
$command = "`"$executablePath`" -p `"Command Prompt`" -d `"%V`""
$label = "Open Terminal here"
$icon = "$executablePath"
VM-Add-To-Right-Click-Menu -menuKey $toolName -menuLabel $label -command $command -menuIcon $icon -type "directory" -background
} catch {
VM-Write-Log-Exception $_
}
}
3 changes: 2 additions & 1 deletion packages/windows-terminal.vm/tools/chocolateyuninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Import-Module vm.common -Force -DisableNameChecking
$toolName = 'Windows Terminal'
$category = 'Productivity Tools'

VM-Uninstall $toolName $category
VM-Uninstall $toolName $category
VM-Remove-From-Right-Click-Menu -menuKey $toolName -type "directory" -background
2 changes: 1 addition & 1 deletion packages/windows-terminal.vm/windows-terminal.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>windows-terminal.vm</id>
<version>1.19.10573.20240305</version>
<version>1.19.10573.20240402</version>
<authors>Microsoft</authors>
<description>Windows Terminal is a new, modern, feature-rich, productive terminal application for command-line users.</description>
<dependencies>
Expand Down