added Create-Shortcut function to Tools.ps1
updated Install-Wireguard to create a desktop shortcut after installation
This commit is contained in:
@@ -395,3 +395,33 @@ Function End-Process
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Function Create-Shortcut {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][string]$Path,
|
||||
[Parameter(Mandatory=$true)][string]$TargetPath,
|
||||
[Parameter(Mandatory=$false)][string]$Arguments,
|
||||
[Parameter(Mandatory=$false)][string]$Description,
|
||||
[Parameter(Mandatory=$false)][string]$Icon = '',
|
||||
[Parameter(Mandatory=$false)][string]$WorkingDirectory = ''
|
||||
)
|
||||
If ( Test-Path $TargetPath ) {
|
||||
If ( Test-Path $Path ) {
|
||||
LogMsg "Deleting existing shortcut at ""${Path}"""
|
||||
Try { Remove-Item $Path -Force -ErrorAction SilentlyContinue }
|
||||
Catch { LogErr $_.Exception.Message }
|
||||
}
|
||||
If ( $WorkingDirectory -eq '' ) { $WorkingDirectory = Split-Path $TargetPath -Parent }
|
||||
If ( $Icon -eq '' ) { $Icon = "${TargetPath}, 0" }
|
||||
$WshShell = New-Object -ComObject WScript.Shell
|
||||
$Shortcut = $WshShell.CreateShortcut($Path)
|
||||
$Shortcut.Arguments = $Arguments
|
||||
$Shortcut.Description = $Description
|
||||
$Shortcut.IconLocation = $Icon
|
||||
$Shortcut.WorkingDirectory = $WorkingDirectory
|
||||
$Shortcut.TargetPath = $TargetPath
|
||||
Try { $Shortcut.Save() }
|
||||
Catch { LogErr $_.Exception.Message }
|
||||
}
|
||||
Else { LogMsg "The target path does not exist" }
|
||||
}
|
||||
Reference in New Issue
Block a user