diff --git a/Install-Wireguard.ps1 b/Install-Wireguard.ps1 index 4a4d258..0157451 100644 --- a/Install-Wireguard.ps1 +++ b/Install-Wireguard.ps1 @@ -3,12 +3,17 @@ If ( IsAdmin ) { $URL = "https://download.wireguard.com/windows-client/wireguard-installer.exe" - ## Install package + ## Download package $Installer = Download-File -URL $URL If ( Test-Path $Installer ) { + + ## Install package End-Process -Name "wireguard" -Match -Force Install-Program -Path "${Installer}" -Delete End-Process -Name "wireguard" -Match -Force + + ## Create shortcut on Public desktop + Create-Shortcut -Path "${Env:Public}\Desktop\WireGuard.LNK" -TargetPath "${Env:ProgramFiles}\WireGuard\wireguard.exe" -Description "WireGuard: Fast, Modern, Secure VPN Tunnel" } Else { LogMsg "The Wireguard installer was not downloaded properly" } } diff --git a/Tools.ps1 b/Tools.ps1 index a5ea49a..86ea874 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -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" } +} \ No newline at end of file