mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-04-01 17:12:09 +00:00
Fix setting PowerShell window title
This commit is contained in:
parent
fd8edde129
commit
25a239608d
@ -78,17 +78,38 @@ if ($processCmd -ne $powershellCmd) {
|
||||
$launchArguments = "$powershellCmd $launchArguments"
|
||||
}
|
||||
|
||||
# Set the title of the running PowerShell instance
|
||||
# Store the script's directory in $ScriptDirectory
|
||||
# Note: This is not used with -WorkingDirectory but
|
||||
# is used in the PowerShell instance's window title.
|
||||
if ($MyInvocation.MyCommand.Path) {
|
||||
$ScriptDirectory = "$(Split-Path $MyInvocation.MyCommand.Path)"
|
||||
} elseif ($PSScriptRoot) {
|
||||
$ScriptDirectory = "$($PSScriptRoot)"
|
||||
} else {
|
||||
$ScriptDirectory = "$($PWD)"
|
||||
}
|
||||
|
||||
# Create the base titles used for naming the instance
|
||||
$FallbackWindowTitle = "$ScriptDirectory\winutil.ps1"
|
||||
$BaseWindowTitle = if ($MyInvocation.MyCommand.Path) {
|
||||
$MyInvocation.MyCommand.Path
|
||||
} else {
|
||||
$MyInvocation.MyCommand.Definition
|
||||
}
|
||||
|
||||
$Host.UI.RawUI.WindowTitle = if ($isElevated) {
|
||||
$BaseWindowTitle + " (Admin)"
|
||||
} else {
|
||||
$BaseWindowTitle + " (User)"
|
||||
# Append (User) or (Admin) prefix to the window title
|
||||
try {
|
||||
$Host.UI.RawUI.WindowTitle = if ($isElevated) {
|
||||
$BaseWindowTitle + " (Admin)"
|
||||
} else {
|
||||
$BaseWindowTitle + " (User)"
|
||||
}
|
||||
} catch {
|
||||
$Host.UI.RawUI.WindowTitle = if ($isElevated) {
|
||||
"$FallbackWindowTitle (Admin)"
|
||||
} else {
|
||||
"$FallbackWindowTitle (User)"
|
||||
}
|
||||
}
|
||||
|
||||
# Relaunch the script as administrator if necessary
|
||||
|
Loading…
Reference in New Issue
Block a user