mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-16 01:40:35 -06:00
Modify Shortcut creation to use PS7 if possible
This commit is contained in:
parent
e262af617d
commit
a887ad433f
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user