ODE: How to Create a Shortcut on the Desktop with ODEID: Q182606 
  | 
Microsoft Office 97 Developer Edition Tools does not provide a way to
create a shortcut outside of the application's program group. This article
demonstrates how to create a shortcut on the desktop using Visual Basic for
Applications and batch (*.bat) files.
This article assumes that you are familiar with Visual Basic for
Applications, the Microsoft Office Developers Edition Setup Wizard, and
with creating Microsoft Access applications using the programming tools
provided with Microsoft Access. For more information about Visual Basic for
Applications, please refer to the "Building Applications with Microsoft
Access 97" manual.
Microsoft provides programming examples for illustration only, without warranty 
either expressed or implied, including, but not limited to, the implied warranties of 
merchantability and/or fitness for a particular purpose. This article assumes that you 
are familiar with the programming language being demonstrated and the tools used to 
create and debug procedures. Microsoft support professionals can help explain the functionality 
of a particular procedure, but they will not modify these examples to provide added 
functionality or construct procedures to meet your specific needs. If you have limited 
programming experience, you may want to contact a Microsoft Certified  Solution Provider 
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
Script.bat         Script.bat is copied to the folder where Windows runs
                   and is started at the end of setup. Script.bat runs
                   Copyshortcut.mdb and waits until it has completed its
                   work before running Cleanup.bat.
CopyShortcut.mdb   CopyShortcut.mdb contains code that copies a shortcut
                   from its location in the application's program group
                   to the computer's desktop. It also creates Cleanup.bat
                   on the user's computer.
Cleanup.bat        Cleanup.bat first deletes Script.bat and
                   CopyShortcut.mdb, which are no longer needed after the
                   shortcut on the desktop has been created. Cleanup.bat
                   then deletes itself. 
NOTE: On Microsoft Windows NT, the Command window created by Script.bat
closes, while on Microsoft Windows 95 it remains open and must be closed by
the user.
       Option Compare Database
       Option Explicit
       ' Declare variables.
       Dim DesktopPath As String
       Dim StartMenuPath As String
       Dim WinPath As String
       Dim fNameOld As String
       Dim fNameNew As String
       ' Declare Public variables.
       Public Type ShortItemId
            cb As Long
            abID As Byte
       End Type
       Public Type ITEMIDLIST
            mkid As ShortItemId
       End Type
       ' Declare constants.
       Const CSIDL_TEMPLATES = &H15
       Const CSIDL_STARTMENU = &HB
       Const CSIDL_FAVORITES = &H6
       Const CSIDL_DESKTOPDIRECTORY = &H10
       ' Declare API functions.
       Public Declare Function SHGetPathFromIDList Lib "shell32.dll" _
          (ByVal pidl As Long, ByVal pszPath As String) As Long
       Public Declare Function SHGetSpecialFolderLocation Lib _
          "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder _
          As Long, pidl As ITEMIDLIST) As Long
       Function GetSpecialFolder(CSIDL As Long) As String
          Dim idlstr As Long
          Dim sPath As String
          Dim IDL As ITEMIDLIST
          Const NOERROR = 0
          Const MAX_LENGTH = 260
          On Error Goto Err_GetFolder
          ' Fill the idl structure with the specified folder item.
          idlstr = SHGetSpecialFolderLocation _
             (Application.hWndAccessApp, CSIDL, IDL)
          If idlstr = NOERROR Then
               ' Get the path from the idl list, and return
               ' the folder with a slash at the end.
               sPath = Space$(MAX_LENGTH)
               idlstr = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath)
                  If idlstr Then
                    GetSpecialFolder = Left$(sPath, InStr(sPath, Chr$(0)) _
                      - 1) & "\"
                  End If
          End If
        Exit_GetFolder:
           Exit Function
        Err_GetFolder:
           Msgbox err.description, vbCritical or VbokOnly
           Resume Exit_GetFolder
       End Function
       Function CopyAppShortcut()
          ' Turn off screen updating.
          Application.Echo False
          ' Call the GetSpecialFolder function to get the location
          ' of the Desktop, Start Menu, and Windows directories.
          DesktopPath = GetSpecialFolder(CSIDL_DESKTOPDIRECTORY)
          StartMenuPath = GetSpecialFolder(CSIDL_STARTMENU)
          WinPath = Left(GetSpecialFolder(CSIDL_TEMPLATES), _
             Len(GetSpecialFolder(CSIDL_TEMPLATES)) - 9)
          ' If there is a problem in getting the paths, then
          ' show an error message and exit.
          If DesktopPath = "" Or StartMenuPath = "" Or WinPath = "" Then
               Application.Echo True
               MsgBox "Error retrieving folder paths." & Chr(13) & _
                  "Unable to copy shortcut to desktop."
               Exit Function
          End If
          ' Copy the shortcut from its program group to the Desktop.
          FileCopy StartMenuPath & "Programs\Northwind\Northwind.lnk", _
             DesktopPath & "\Northwind.lnk"
          ' NOTE: It is necessary to modify the following lines of code to
          ' match your application's path and shortcut's name.
          '
          '   "Programs\Northwind\Northwind.lnk"
          '
          ' should be modified to read:
          '
          '   "Programs\Path To Your Application\Your Shortcut Name.lnk"
          '
          ' -and-
          '
          '   "\Northwind.lnk"
          '
          ' should be modified to read:
          '
          '   "\Your Shortcut Name.lnk"
          ' Create the batch file Cleanup.bat, which will
          ' run after CopyShortCut.mdb is closed.
          Open WinPath & "Cleanup.bat" For Output As #1
          Print #1, "del " & WinPath & "Script.bat"
          Print #1, "del " & WinPath & "CopyShortcut.mdb"
          Print #1, "Echo Northwind Setup is now complete."
          Print #1, "Echo Close this DOS window "
          Print #1, "Echo by clicking on the X"
          Print #1, "Echo at the top right..."
          Print #1, "Echo :)"
          Print #1, "Echo :)"
          Print #1, "Echo :)"
          Print #1, "Echo :)"
          Print #1, "Echo :)"
          Print #1, "Echo :)"
          Print #1, "Del " & WinPath & "Cleanup.bat"
          Close #1
          ' After Cleanup.bat is created, close
          ' Microsoft Access.
       Exit_CopyAppShortcut:
            Application.quit
       Err_GetFolder:
           Application.echo True
           Msgbox err.description, vbCritical or VbokOnly
           Resume Exit_CopyAppShortCut
      End Function 
       Action
       ------
       RunCode
       Action Arguments
       -------------------------------
       Function Name: CopyAppShortCut() Echo Off
Start /wait /min CopyShortcut.mdb
Cls
Call Cleanup.bat
       CopyShortcut.mdb
       ----------------
       Destination Folder: $(WinPath)
       Script.bat
       ----------
       Destination Folder: $(WinPath)
       Northwind.mdb
       -------------
       Destination Folder: $(AppPath)
       Set As Application's Main File: Checked 
     After you've added these files, click Next.
       Shortcut for Northwind.mdb
       --------------------------
       General Shortcut Properties
            Description: Northwind
       Database Shortcut Properties
            Database Command-Line Options: Run-time 
     Click Next twice to bypass the Registry Values screen, and respond
     to any prompts from the Setup Wizard.
       Microsoft Access Run-Time Version
       Workgroup Administrator "$(FilePath)\Script.bat"
For more information about including an executable file with your custom
Setup program, search the Help Index for "Setup Wizard, files to run
after Setup."
Or see the following article in the Microsoft Knowledge Base:
Q163062 ODE97: Errors Executing File After Custom Setup
Additional query words: icon icons
Keywords          : kbdta PgmHowto OdeGen 
Version           : 
Platform          : WINDOWS 
Issue type        : kbhowto 
Last Reviewed: August 3, 1999