Create Desktop Shortcut

Code Properties

  • Language: PowerShell
  • COM Objects: WScript.Shell

Overview

Simple PowerShell script that creates a desktop shortcut (.lnk file) using the Windows Script Host Shell COM object.

Code

$TargetFile = "$Env:SYSTEMROOT\System32\notepad.exe"
$ShortcutFile = "$Env:Public\Desktop\Notepad.lnk"
$Wsh = New-Object -ComObject WScript.Shell
$Shortcut = $Wsh.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()

Usage

Modify $TargetFile and $ShortcutFile variables to create shortcuts for different applications:

# create shortcut for custom application
$TargetFile = "C:\Program Files\MyApp\app.exe"
$ShortcutFile = "$Env:USERPROFILE\Desktop\MyApp.lnk"
$Wsh = New-Object -ComObject WScript.Shell
$Shortcut = $Wsh.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Arguments = "--start-minimized"
$Shortcut.WorkingDirectory = "C:\Program Files\MyApp"
$Shortcut.IconLocation = "$TargetFile,0"
$Shortcut.Save()

Appendix

Note created on 2024-05-03 and last modified on 2024-12-31.

See Also


(c) No Clocks, LLC | 2024