mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-04-02 17:32: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"
|
$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) {
|
$BaseWindowTitle = if ($MyInvocation.MyCommand.Path) {
|
||||||
$MyInvocation.MyCommand.Path
|
$MyInvocation.MyCommand.Path
|
||||||
} else {
|
} else {
|
||||||
$MyInvocation.MyCommand.Definition
|
$MyInvocation.MyCommand.Definition
|
||||||
}
|
}
|
||||||
|
|
||||||
$Host.UI.RawUI.WindowTitle = if ($isElevated) {
|
# Append (User) or (Admin) prefix to the window title
|
||||||
$BaseWindowTitle + " (Admin)"
|
try {
|
||||||
} else {
|
$Host.UI.RawUI.WindowTitle = if ($isElevated) {
|
||||||
$BaseWindowTitle + " (User)"
|
$BaseWindowTitle + " (Admin)"
|
||||||
|
} else {
|
||||||
|
$BaseWindowTitle + " (User)"
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
$Host.UI.RawUI.WindowTitle = if ($isElevated) {
|
||||||
|
"$FallbackWindowTitle (Admin)"
|
||||||
|
} else {
|
||||||
|
"$FallbackWindowTitle (User)"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Relaunch the script as administrator if necessary
|
# Relaunch the script as administrator if necessary
|
||||||
|
Loading…
Reference in New Issue
Block a user