T
Tom
How do I create a shortcut to a file that doesn't exist on my computer/
network?
Bascially, what I want to do is create a shortcut to a file that
exists on somebody else's server, then send it to them so that they
can click on it to execute a batch file. The batch file copies a
master copy of an .mdb from the server to their local hard drive (over
writing any existing copy), then runs the .mdb with a command
arguement to point to the data file back end.
The path is a UNC path, so I can just map something locally.
And, yes, I know the EASIEST thing to do is to call them and walk them
thru the process of creating the shortcut, but where is the fun in
that...besides it looks bush league.
The routine I normall use for creating shortcuts is below, but it
won't work. I believe windows (not so) helpfully validates the
existance of a file before it will create a shortcut.
Suggestions, or alternate ideas to accomplish the same ends would be
much appreciated.
Function fCreateShortcutOnDesktop(strFullFilePathName As String,
strIconFileName As String) 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 =
'===================================================================
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
' Read desktop path using WshSpecialFolders object
strDesktopPath = WSHShell.SpecialFolders.Item("Desktop")
' Create a shortcut object on the desktop
Set WSHShortcut = WSHShell.CreateShortcut _
(strDesktopPath & "\" & "CATERS" & ".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
network?
Bascially, what I want to do is create a shortcut to a file that
exists on somebody else's server, then send it to them so that they
can click on it to execute a batch file. The batch file copies a
master copy of an .mdb from the server to their local hard drive (over
writing any existing copy), then runs the .mdb with a command
arguement to point to the data file back end.
The path is a UNC path, so I can just map something locally.
And, yes, I know the EASIEST thing to do is to call them and walk them
thru the process of creating the shortcut, but where is the fun in
that...besides it looks bush league.
The routine I normall use for creating shortcuts is below, but it
won't work. I believe windows (not so) helpfully validates the
existance of a file before it will create a shortcut.
Suggestions, or alternate ideas to accomplish the same ends would be
much appreciated.
Function fCreateShortcutOnDesktop(strFullFilePathName As String,
strIconFileName As String) 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 =
'===================================================================
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
' Read desktop path using WshSpecialFolders object
strDesktopPath = WSHShell.SpecialFolders.Item("Desktop")
' Create a shortcut object on the desktop
Set WSHShortcut = WSHShell.CreateShortcut _
(strDesktopPath & "\" & "CATERS" & ".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