mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 22:55:52 -06:00
Optimized: Shortcut Creation and PS7 Tweak (#2314)
* Clarified the wording * Handle Computers without Windows Terminal (eg Win10) * Modify Shortcut creation to use PS7 if possible
This commit is contained in:
parent
e5ba389606
commit
d4faee5fbc
@ -2305,8 +2305,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"WPFTweaksPowershell7": {
|
"WPFTweaksPowershell7": {
|
||||||
"Content": "Replace Default Powershell 5 to Powershell 7",
|
"Content": "Change Windows Terminal default: PowerShell 5 -> PowerShell 7",
|
||||||
"Description": "This will edit the config file of the Windows Terminal Replacing the Powershell 5 to Powershell 7 and install Powershell 7 if necessary",
|
"Description": "This will edit the config file of the Windows Terminal replacing PowerShell 5 with PowerShell 7 and installing PS7 if necessary",
|
||||||
"category": "Essential Tweaks",
|
"category": "Essential Tweaks",
|
||||||
"panel": "1",
|
"panel": "1",
|
||||||
"Order": "a009_",
|
"Order": "a009_",
|
||||||
|
@ -17,14 +17,20 @@ function Invoke-WPFShortcut {
|
|||||||
[bool]$RunAsAdmin = $false
|
[bool]$RunAsAdmin = $false
|
||||||
)
|
)
|
||||||
|
|
||||||
# Preper the Shortcut Fields and add an a Custom Icon if it's available at "$env:TEMP\cttlogo.png", else don't add a Custom Icon.
|
# add an a Custom Icon if it's available at "$env:TEMP\cttlogo.png", else don't add a Custom Icon.
|
||||||
$iconPath = $null
|
$iconPath = $null
|
||||||
Switch ($ShortcutToAdd) {
|
Switch ($ShortcutToAdd) {
|
||||||
"WinUtil" {
|
"WinUtil" {
|
||||||
$SourceExe = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"
|
# Use Powershell 7 if installed and fallback to PS5 if not
|
||||||
$IRM = 'irm https://christitus.com/win | iex'
|
if (Get-Command "pwsh" -ErrorAction SilentlyContinue){
|
||||||
$Powershell = '-ExecutionPolicy Bypass -Command "Start-Process powershell.exe -verb runas -ArgumentList'
|
$shell = "pwsh.exe"
|
||||||
$ArgumentsToSourceExe = "$powershell '$IRM'"
|
}
|
||||||
|
else{
|
||||||
|
$shell = "powershell.exe"
|
||||||
|
}
|
||||||
|
|
||||||
|
$shellArgs = "-ExecutionPolicy Bypass -Command `"Start-Process $shell -verb runas -ArgumentList `'-Command `"irm https://christitus.com/win | iex`"`'"
|
||||||
|
|
||||||
$DestinationName = "WinUtil.lnk"
|
$DestinationName = "WinUtil.lnk"
|
||||||
|
|
||||||
Invoke-WebRequest -Uri "https://christitus.com/images/logo-full.png" -OutFile "$env:TEMP\cttlogo.png"
|
Invoke-WebRequest -Uri "https://christitus.com/images/logo-full.png" -OutFile "$env:TEMP\cttlogo.png"
|
||||||
@ -52,9 +58,9 @@ function Invoke-WPFShortcut {
|
|||||||
# Prepare the Shortcut paramter
|
# Prepare the Shortcut paramter
|
||||||
$WshShell = New-Object -comObject WScript.Shell
|
$WshShell = New-Object -comObject WScript.Shell
|
||||||
$Shortcut = $WshShell.CreateShortcut($FileBrowser.FileName)
|
$Shortcut = $WshShell.CreateShortcut($FileBrowser.FileName)
|
||||||
$Shortcut.TargetPath = $SourceExe
|
$Shortcut.TargetPath = $shell
|
||||||
$Shortcut.Arguments = $ArgumentsToSourceExe
|
$Shortcut.Arguments = $shellArgs
|
||||||
if ($iconPath -ne $null) {
|
if ($null -ne $iconPath) {
|
||||||
$shortcut.IconLocation = $iconPath
|
$shortcut.IconLocation = $iconPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,22 +25,29 @@ function Invoke-WPFTweakPS7{
|
|||||||
$targetTerminalName = "Windows PowerShell"
|
$targetTerminalName = "Windows PowerShell"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# Check if the Windows Terminal is installed and return if not (Prerequisite for the following code)
|
||||||
$settingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
|
if (-not (Get-Command "wt" -ErrorAction SilentlyContinue)){
|
||||||
if (Test-Path -Path $settingsPath) {
|
Write-Host "Windows Terminal not installed. Skipping Terminal preference"
|
||||||
Write-Host "Settings file found."
|
return
|
||||||
$settingsContent = Get-Content -Path $settingsPath | ConvertFrom-Json
|
}
|
||||||
$ps7Profile = $settingsContent.profiles.list | Where-Object { $_.name -eq $targetTerminalName }
|
# Check if the Windows Terminal settings.json file exists and return if not (Prereqisite for the following code)
|
||||||
if ($ps7Profile) {
|
$settingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
|
||||||
$settingsContent.defaultProfile = $ps7Profile.guid
|
if (-not (Test-Path -Path $settingsPath)){
|
||||||
$updatedSettings = $settingsContent | ConvertTo-Json -Depth 100
|
Write-Host "Windows Terminal Settings file not found at $settingsPath"
|
||||||
Set-Content -Path $settingsPath -Value $updatedSettings
|
return
|
||||||
Write-Host "Default profile updated to $targetTerminalName using the name attribute."
|
|
||||||
} else {
|
|
||||||
Write-Host "No PowerShell 7 profile found in Windows Terminal settings using the name attribute."
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Write-Host "Settings file not found at $settingsPath"
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
Write-Host "Settings file found."
|
||||||
|
$settingsContent = Get-Content -Path $settingsPath | ConvertFrom-Json
|
||||||
|
$ps7Profile = $settingsContent.profiles.list | Where-Object { $_.name -eq $targetTerminalName }
|
||||||
|
if ($ps7Profile) {
|
||||||
|
$settingsContent.defaultProfile = $ps7Profile.guid
|
||||||
|
$updatedSettings = $settingsContent | ConvertTo-Json -Depth 100
|
||||||
|
Set-Content -Path $settingsPath -Value $updatedSettings
|
||||||
|
Write-Host "Default profile updated to " -NoNewline
|
||||||
|
Write-Host "$targetTerminalName " -ForegroundColor White -NoNewline
|
||||||
|
Write-Host "using the name attribute."
|
||||||
|
} else {
|
||||||
|
Write-Host "No PowerShell 7 profile found in Windows Terminal settings using the name attribute."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user