I know of three ways to make a Windows shortcut.
I believe number 2 and 3 came from an example I received from someone on
this list a long time ago. These two examples seem to work fine, though,
for some reason, the first places the shortcut in the Recent Items menu. I
think the Recent Items folder is actually at: C:\Documents and
Settings\(CURRENT USER NAME)\Recent
I can't promise that this works on all versions of Windows, but seems to
work fine on XP.
HTH
1) Use a third-party installer program. Some, if not all, will allow you
to do this as well as automatically associate a document extension with your
application.
2)
// 1) Create the shortcut file in the Recent Document folder
// 2) Move the newly created shortcut file in the folder you want
// In order to do the first, you must use the Win32 API function
// SHAddToRecentDocs
// This method doesn't work very well.
// It doesn't create the shortcut unless it's pointing to a document. It
then creates the shortcut to
// the document as well as its containing folder. If you delete these
shortcuts, it doesn't recreate them
// unless you quit and restart the application.
dim originalPath As String
dim any As Integer
dim pathPtr As MemoryBlock
Const SHARD_PATH = &H2
dim originalFolderItem as FolderItem
originalFolderItem = GetFolderItem("C:\RBTESTS\New Text Document.txt")
Declare Function SHAddToRecentDocs Lib "shell32" (ByVal dwFlags As
Integer, ByVal dwData As Ptr) As Integer
originalPath = originalFolderItem.AbsolutePath
pathPtr = newMemoryBlock(lenB(originalPath)+1)
pathPtr.cString(0) = originalPath
any = SHAddToRecentDocs(SHARD_PATH, pathPtr)
3) Make a new method, makeDesktopShortcut: scName as String, scTarget as
FolderItem
Inside this method, add the following:
Dim dtPath, lnkPath As String
Dim targetPath, parentPath As String
Dim lnkObj As OLEObject
Dim scriptShell As New OLEObject("{F935DC22-1CF0-11D0-ADB9-00C04FD58A0B}")
if scriptShell <> Nil then
dtPath = DesktopFolder.AbsolutePath
lnkPath = (dtPath + scName + ".lnk")
targetPath = scTarget.AbsolutePath
parentPath = scTarget.Parent.AbsolutePath
lnkObj = scriptShell.CreateShortcut(lnkPath)
if lnkObj <> Nil then
lnkObj.Description = scName
lnkObj.TargetPath = targetPath
lnkObj.WorkingDirectory = parentPath
lnkObj.Save
end if
end if
Call this method as follows:
// First entry is the name of the shortcut. Second is what the shortcut
points to.
// makeDesktopShortcut only creates shortcuts on the desktop, but you can
modify the Sub.
// Note that it relies on wshom.ocx
makeDesktopShortcut("TheShortcut Name", Volume(0).Child("RBTESTS"))
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>