[AccessD] Creating a shortcut programmatically

jwcolby jwcolby at colbyconsulting.com
Thu Jan 5 09:08:02 CST 2012


And then a new version to add things I need:

Public Enum ShellWindowStyle
     SWS_None = -1
     SWS_Hide = vbHide
     SWS_MaximizedFocus = vbMaximizedFocus
     SWS_MinimizedFocus = vbMinimizedFocus
     SWS_NormalFocus = vbNormalFocus
End Enum


'
' CreateShellShortcut()
'
' TargetName - The file that would be launched when the shortcut is clicked.
' TargetArguments - Command line parameters to TargetName.
' TargetDescription - The description of the shortcut.
' ShortcutFileName - The shortcut file name including the .lnk extension.
'
' Copyright (C) 2002 OfficeOne
' http://support.microsoft.com/kb/244677
'
Sub CreateShellShortcut(ByVal TargetName As String, _
     ByVal TargetArguments As String, _
     ByVal TargetDescription As String, _
     ByVal ShortcutFileName As String, _
     WindowStyle As ShellWindowStyle, _
     Optional strWorkingDir As String = "")

     Dim WSH As Object
     Dim Shortcut As Object
     'dim sc as Wscript.shell.

     Set WSH = CreateObject("WScript.Shell")
     Set Shortcut = WSH.CreateShortcut(ShortcutFileName)
     With Shortcut
         .TargetPath = TargetName
         .Arguments = TargetArguments
         .Description = TargetDescription
         .WindowStyle = WindowStyle
         If Len(strWorkingDir) Then
             .WorkingDirectory = strWorkingDir
         End If
         .Save
     End With
     Set Shortcut = Nothing
     Set WSH = Nothing
End Sub

John W. Colby
Colby Consulting

Reality is what refuses to go away
when you do not believe in it

On 1/5/2012 8:52 AM, jwcolby wrote:
> I am building an application to Copy files and then open one of the files copied which is an Access
> application. I have an Access Fe to handle the data entry for setting up the files being copied etc,
> plus a C# application to handle the actual automation required to do the copy and open. I then point
> the user to a shortcut to perform this Copy and Open.
>
> I found the following code on the internet which allows me to create the shortcut itself
> programmatically using the information entered into the Access tables.
>
> '
> ' CreateShellShortcut()
> '
> ' TargetName - The file that would be launched when the shortcut is clicked.
> ' TargetArguments - Command line parameters to TargetName.
> ' TargetDescription - The description of the shortcut.
> ' ShortcutFileName - The shortcut file name including the .lnk extension.
> '
> ' Copyright (C) 2002 OfficeOne
> '
> Sub CreateShellShortcut(ByVal TargetName As String, _
> ByVal TargetArguments As String, _
> ByVal TargetDescription As String, _
> ByVal ShortcutFileName As String)
>
> Dim WSH As Object
> Dim Shortcut As Object
>
> Set WSH = CreateObject("WScript.Shell")
> Set Shortcut = WSH.CreateShortcut(ShortcutFileName)
> With Shortcut
> .TargetPath = TargetName
> .Arguments = TargetArguments
> .Description = TargetDescription
> .Save
> End With
> Set Shortcut = Nothing
> Set WSH = Nothing
> End Sub
>



More information about the AccessD mailing list