Private Declare Function fCreateShellLink Lib "VB5STKIT.DLL" _
(ByVal lpstrFolderName As String, _
ByVal lpstrLinkName As String, _
ByVal lpstrLinkPath As String, _
ByVal lpstrLinkArgs As String) As Long
Private Sub Command0_Click()
Dim lReturn As Long
Dim Mdesktop As String
Dim Mtarget As String
Mdesktop = "C:\Documents And Settings\Fred\Desktop\"
Mtarget = "C:\Documents And Settings\Fred\My Documents\mdbFiles
\db1.mdb"
'Add to Desktop
lReturn = fCreateShellLink(Mdesktop, "db1", Mtarget, "")
MsgBox lReturn
End Sub
Function fCreateShortcutOnDesktop(strFullFilePathName As String,
strIconFileName As String, Optional strShortcutPath As String,
Optional strShortcutName As String = "XXX") As Long
'===================================================================
'= Procedure: fCreateShortcutOnDesktop =
'= Type: Function =
'= =
'= Purpose: Uses the Windows Scripting Host to create a .lnk =
'= shortcut on the user's desktop. Assumes a =
'= reference has been establised to the WSH object =
'= library using Tools->References in the VBE. =
'= Parameters: strFullFilePathName - String - The full name of =
'= the file to which the shortcut will point. =
'= Returns: Long - 1 on success, 0 if the target did not =
'= exist, -1 if an unexpected error occurred. =
'= =
'= Version: Date: Developer: Action: =
'=---------|---------|---------------|-----------------------------=
'= 1.0.0 |19-Jul-99| Robert Bruce | Created =
'= 1.0.0a |08-Jun-00| Tom Mitchell |allow designation of icon =
'= 1.0.1 |04-Sep-08| Tom Mitchell |allow optional designation of a
different location for shortcut
'===================================================================
Dim WSHShell As IWshRuntimeLibrary.IWshShell_Class
Dim WSHShortcut As IWshRuntimeLibrary.IWshShortcut_Class
Dim strDesktopPath As String
Dim strFileName As String
Dim strPath As String
On Error GoTo fCreateShortcutOnDesktop_Err
' Create a Windows Shell Object
Set WSHShell = New IWshRuntimeLibrary.IWshShell_Class
' Get the file's name and path...
strFileName = Dir(strFullFilePathName)
strPath = Left(strFullFilePathName, _
Len(strFullFilePathName) - Len(strFileName))
' Make sure file exists
If Not Len(strFileName) = 0 Then
'figure out where the shortcut is going...
If Len(strShortcutPath) <> 0 Then
strDesktopPath = strShortcutPath
Else
strDesktopPath = WSHShell.SpecialFolders.Item("Desktop") '
Read desktop path using WshSpecialFolders object
End If
' Create a shortcut object at the proper location with the proper
name
Set WSHShortcut = WSHShell.CreateShortcut _
(strDesktopPath & "\" & strShortcutName & ".lnk")
' Set shortcut object properties and save it
With WSHShortcut
.TargetPath = WSHShell. _
ExpandEnvironmentStrings(strFullFilePathName)
.WorkingDirectory = WSHShell. _
ExpandEnvironmentStrings(strPath)
.WindowStyle = 4
.IconLocation = WSHShell. _
ExpandEnvironmentStrings(strIconFileName & " ,
0")
.Save
End With
fCreateShortcutOnDesktop = 1
Else
fCreateShortcutOnDesktop = 0
End If
Continue:
' Tidy Up
Set WSHShell = Nothing
Exit Function
fCreateShortcutOnDesktop_Err:
fCreateShortcutOnDesktop = -1
Resume Continue
End Function
>Has anyone used VB5STKIT.DLL ?
No. I don't recall exactly where I got the code but the page at
http://www.thescarms.com/vbasic/shelllnk.aspx is what I use in the Auto FE Updater.
Note that while you do create a reference to the shelllnk.tlb file you don't actually
need to distribute it with your application.
shelllnk.tlb is the keyword to use in searching for this code.
Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
Granite Fleet Manager http://www.granitefleet.com/
Dim WScript As Object
Dim MyIcon As Object
Dim Mloc As String
Dim Mname As String
Set WScript = CreateObject("WScript.Shell")
Mloc = "H:\Windows NT 5.1 Workstation Profile\Desktop\"
Mname = "TestShortcut.lnk"
Set MyIcon = WScript.CreateShortcut(Mloc & Mname)
MyIcon.TargetPath = "I:\DB Apps\Batches\File.mdb"
MyIcon.Save
Set MyIcon = Nothing
Set WScript = Nothing
On Jan 4, 5:02 pm, "zuckerm...@gmail.com" <zuckerm...@gmail.com>
wrote: