OT (kind of) - Create Shortcut

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
 
T

Tom

That's the problem - how do I get the same path name as the other
person...

Their file will be located on \\TheirServer\path\File.bat. I don't
have the equivalent on my network and can't create such AFAIK.
 
T

Tony Toews [MVP]

Tom said:
How do I create a shortcut to a file that doesn't exist on my computer/
network?

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.

I don't know that you can programmatically create a shortcut pointing
to something that doesn't exist.

As an alternative why not just create a shortcut on the root of a
network share and get the user to click on that shortcut.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
T

Tom

Thanks to all for offering suggestions. After a couple nights sleep,
I decided that the best thing to do was to include code for making the
BAT file and shortcut in the MDB. True, they would have to run the DB
once not using the shortcut, but that didn't seem like too big a down
side to save me alot of work trying to get around the problems I was
encountering. Plus, they'd have a self contained way to recreate all
the files needed after I have left the project.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top