WSH » wshshell » CreateShortcut

WshShell.CreateShortcut (strPathName)

The CreateShortcut method creates and returns a WshShortcut object.

The CreateShortcut method creates either a WshShortcut or WshURLShortcut object depending on the specified strPathName. If strPathName has the extension ".lnk", then a WshShortcut object is created and returned. If strPathName has the extension ".url", then a WshURLShortcut object is created and returned.

If strPathName points to a file that already exists, then the shortcut file is opened and can be modified via the shortcut object returned by CreateShortcut. Otherwise, the shortcut file will not be created until the Save method of the shortcut object is called.


Set WshShell = CreateObject("WScript.Shell")
strDesktopPath = WshShell.SpecialFolders("Desktop")

Set objShortcutLnk = WshShell.CreateShortcut(strDesktopPath & "\notepad.lnk")
objShortcutLnk.TargetPath = "notepad"

Set objShortcutUrl = WshShell.CreateShortcut(strDesktopPath & "\devguru.url")
objShortcutUrl.TargetPath = ""

This VBScript code creates one program shortcut to Notepad and one URL shortcut to the DevGuru web site, then saves both shortcuts on the user's desktop.

Language(s): VBScript