Method:  WshShell.CreateShortcut

WshShell.CreateShortcut strPathName

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.

The following 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.

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

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

Set objShortcutUrl = WshShell.CreateShortcut(strDesktopPath & "\devguru.url")
objShortcutUrl.TargetPath = "http://www.devguru.com"
objShortcutUrl.Save


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information