Saturday, March 23, 2013

Creating Desktop Shortcuts using Powershell

If you've been wanting to create shortcuts using Powershell and all the examples on the web don't work then you've come to the right spot.

Aside from the code provided here, you can also download my free tool at:

http://download.cnet.com/Powershell-Shortcut-Builder/3000-2344_4-76168548.html

For Access:

$ws = New-Object -com WScript.Shell
$Dt = $ws.SpecialFolders.Item("Desktop")
$Scp = Join-Path -Path $Dt -ChildPath "Access.lnk"
$Sc = $ws.CreateShortcut($Scp)
$Sc.TargetPath = "C:\Program Files (x86)\Microsoft Office\Office15\MSAccess.exe"
$Sc.Description = "Access Link"
$Sc.Save()

For the Calculator:

$ws = New-Object -com WScript.Shell
$Dt = $ws.SpecialFolders.Item("Desktop")
$Scp = Join-Path -Path $Dt -ChildPath "Calc.lnk"
$Sc = $ws.CreateShortcut($Scp)
$Sc.TargetPath = "Calc"
$Sc.Save()

For Disk Management:

$ws = New-Object -com WScript.Shell
$Dt = $ws.SpecialFolders.Item("Desktop")
$Scp = Join-Path -Path $Dt -ChildPath "diskmgmt.lnk"
$Sc = $ws.CreateShortcut($Scp)
$Sc.TargetPath = "diskmgmt.msc"
$Sc.Description = "Disk Management Link"
$Sc.Save()

For Excel:

$ws = New-Object -com WScript.Shell
$Dt = $ws.SpecialFolders.Item("Desktop")
$Scp = Join-Path -Path $Dt -ChildPath "Excel.lnk"
$Sc = $ws.CreateShortcut($Scp)
$Sc.TargetPath = "C:\Program Files (x86)\Microsoft Office\Office15\Excel.exe"
$Sc.Description = "Excel Link"
$Sc.Save()

For MSPaint:

$ws = New-Object -com WScript.Shell
$Dt = $ws.SpecialFolders.Item("Desktop")
$Scp = Join-Path -Path $Dt -ChildPath "MSPaint.lnk"
$Sc = $ws.CreateShortcut($Scp)
$Sc.TargetPath = "MSPaint.exe"
$Sc.Description = "MSPaint Link"
$Sc.Save()

For Notepad:

$ws = New-Object -com WScript.Shell
$Dt = $ws.SpecialFolders.Item("Desktop")
$Scp = Join-Path -Path $Dt -ChildPath "Notepad.lnk"
$Sc = $ws.CreateShortcut($Scp)
$Sc.TargetPath = "Notepad.exe"
$Sc.Description = "Notepad Link"
$Sc.Save()

For Word:

$ws = New-Object -com WScript.Shell
$Dt = $ws.SpecialFolders.Item("Desktop")
$Scp = Join-Path -Path $Dt -ChildPath "Word.lnk"
$Sc = $ws.CreateShortcut($Scp)
$Sc.TargetPath = "C:\Program Files (x86)\Microsoft Office\Office15\winword.exe"
$Sc.Description = "Winword Link"
$Sc.Save()

For Wordpad:

$ws = New-Object -com WScript.Shell
$Dt = $ws.SpecialFolders.Item("Desktop")
$Scp = Join-Path -Path $Dt -ChildPath "Wordpad.lnk"
$Sc = $ws.CreateShortcut($Scp)
$Sc.TargetPath = "C:\Program Files (x86)\Windows NT\Accessories\Wordpad.exe"
$Sc.Description = "Wordpad Link"
$Sc.Save()

Also, if you want to add a link to this blog:

$ws = New-Object -comObject WScript.Shell
$Dt = $ws.SpecialFolders.item("Desktop")
$URL = $ws.CreateShortcut($Dt + "\Powershell Pain Relief.url")
$URL.TargetPath = "http://powershellpainrelief.blogspot.com"
$URL.Save()

No comments:

Post a Comment