Skip to content

Commit 47f569d

Browse files
committed
Add some preliminary code for running elevated scripts in Windows Terminal
1 parent 3d53a21 commit 47f569d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Utils.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,18 @@ function Elevate {
164164
}
165165
else {
166166
Show-Output "This script requires admin access. Elevating."
167-
Show-Output "$command"
167+
Show-Output "${command}"
168+
$ArgumentList = ('-NoProfile -NoExit -Command "cd {0}; {1} -Elevated"' -f ($pwd, $command))
168169
# Use newer PowerShell if available.
169170
if (Test-CommandExists "pwsh") {$shell = "pwsh"} else {$shell = "powershell"}
170-
Start-Process -FilePath "$shell" -Verb RunAs -ArgumentList ('-NoProfile -NoExit -Command "cd {0}; {1}" -Elevated' -f ($pwd, $command))
171+
# Use Windows Terminal if available
172+
# if (Test-CommandExists "wt") {
173+
# # https://stackoverflow.com/a/63163528
174+
# # This has problems in parsing the semicolon
175+
# Start-Process -FilePath "wt" -Verb RunAs -ArgumentList ('new-tab {0} {1}' -f ($shell, $ArgumentList))
176+
# } else {
177+
Start-Process -FilePath "$shell" -Verb RunAs -ArgumentList "${ArgumentList}"
178+
# }
171179
Show-Output "The script has been started in another window. You can close this window now." -ForegroundColor Green
172180
}
173181
Exit

0 commit comments

Comments
 (0)