mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-17 18:27:42 -06:00
Simple improvement: make WinUtil's Shortcut Function Do Less (Lazier) (#1903)
* Add Extra Comments to 'Invoke-WPFShortcut' to make the Logic a Bit Clearer * Make The 'Invoke-WPFShortcut' Function Lazier for Added Efficiency and to not Display False Info whenever the User Cancels the 'Save As' Operation
This commit is contained in:
parent
bdf9c8378c
commit
f5f506b9c5
@ -17,6 +17,7 @@ function Invoke-WPFShortcut {
|
||||
[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.
|
||||
$iconPath = $null
|
||||
Switch ($ShortcutToAdd) {
|
||||
"WinUtil" {
|
||||
@ -33,11 +34,18 @@ function Invoke-WPFShortcut {
|
||||
}
|
||||
}
|
||||
|
||||
# Show a File Dialog Browser, to let the User choose the Name and Location of where to save the Shortcut
|
||||
$FileBrowser = New-Object System.Windows.Forms.SaveFileDialog
|
||||
$FileBrowser.InitialDirectory = [Environment]::GetFolderPath('Desktop')
|
||||
$FileBrowser.Filter = "Shortcut Files (*.lnk)|*.lnk"
|
||||
$FileBrowser.FileName = $DestinationName
|
||||
$FileBrowser.ShowDialog() | Out-Null
|
||||
|
||||
# Do an Early Return if The Save Shortcut operation was cancel by User's Input.
|
||||
$FileBrowserResult = $FileBrowser.ShowDialog()
|
||||
$DialogResultEnum = New-Object System.Windows.Forms.DialogResult
|
||||
if (-not ($FileBrowserResult -eq $DialogResultEnum::OK)) {
|
||||
return
|
||||
}
|
||||
|
||||
$WshShell = New-Object -comObject WScript.Shell
|
||||
$Shortcut = $WshShell.CreateShortcut($FileBrowser.FileName)
|
||||
|
Loading…
Reference in New Issue
Block a user