John Topley's Knowledgebase

Send To Desktop As Shortcut

Friday, 30 May 2003

This Windows Script Host script duplicates the functionality of the "Send to Desktop as Shortcut" menu item, which was originally a Windows Powertoy and then built-in to later versions of Windows.

Download SendToDesktop.vbs

' Script to create a desktop shortcut to the selected object.
' Place a shortcut to this script in your Windows SendTo folder.
Option Explicit
Const strNormalWindow = 4

Private fsoFileSystem
Private objArgs
Private objShellLink
Private strBaseName
Private strDesktop
Private strShortcutPath
Private wshShell

Set wshShell = WScript.CreateObject("WScript.Shell")
Set objArgs = WScript.Arguments
Set fsoFileSystem = CreateObject("Scripting.FileSystemObject")  

strDesktop = wshShell.SpecialFolders("Desktop")

' Strip path and file extension from command-line argument.
strBaseName = fsoFileSystem.GetBaseName(objArgs(0))

' Uncomment the next line and comment the following line
' if you like shortcuts labelled explicitly.
'strShortcutPath = strDesktop & "\Shortcut to " & strBaseName
  &".lnk"
strShortcutPath = strDesktop & "\" & strBaseName
  & ".lnk"

' Only create the shortcut if it doesn't already exist.
If Not fsoFileSystem.FileExists(strShortcutPath) Then
 Set objShellLink = wshShell.CreateShortcut(strShortcutPath)

 With objShellLink
  .TargetPath = objArgs(0)
  .WindowStyle = strNormalWindow
  .IconLocation = objArgs(0) & ", 0"
  .WorkingDirectory = strDesktop
  .Save
 End With

 Set objShellLink = Nothing
End If

Set fsoFileSystem = Nothing
Set wshShell = Nothing

top | index | previous | next | comments ()

home | archive | kb | media | about | contact | accessibility
Copyright © 2003 - 2005 John Topley. Made with CityDesk.