MOD2000: How to Create a Desktop Shortcut for Your Solution

ID: Q244868


The information in this article applies to:
  • Microsoft Office 2000 Developer


SUMMARY

The Package and Deployment Wizard provided by Microsoft Office 2000 Developer does not provide a way to create a shortcut outside of the Windows menu structure. This article demonstrates how to create a shortcut on the Desktop using Visual Basic for Applications and batch (*.bat) files.

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


MORE INFORMATION

This example uses or creates the following files:


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, and on Microsoft Windows 95/98 it remains open and must be closed by the user.

The following steps demonstrate how to create the additional files discussed earlier in this article and how to distribute them with your solution using the Package and Deployment Wizard.

How to Create CopyShortcut.mdb and Script.bat

  1. In Access, create a new database called CopyShortcut.mdb.


  2. In the new database, create a new module and type the code below.

    NOTE: For your solution, you must make one change to the module, detailed in the "IMPORTANT" comment in the code below.


  3. 
    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"
    
       ' IMPORTANT: This FileCopy command is what copies the shortcut from 
       ' its location in the Programs menu to the desktop. It is necessary
       ' to modify the above line of code to match your application's shortcut
       ' folder and shortcut name. You can name them here and later in the 
       ' Package and Deployment Wizard (step 7 of Creating the Package).
       ' Make sure they are given the same name there as well.
       '
       '   "Programs\Northwind\Northwind.lnk"
       '
       ' should be modified to read:
       '
       '   "Programs\<Your Shortcut Folder>\<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, "Echo Off"
       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 
  4. Save the new module as DeskTopShortcuts.


  5. Create the following new macro and name it AutoExec:


  6. 
       Action
       ------
       RunCode
    
       Action Arguments
       -------------------------------
       Function Name: CopyAppShortCut() 
  7. Save the macro.

    NOTE: When you name a macro AutoExec, it will run each time the database is opened. To open the database without running the AutoExec macro, press SHIFT until the database opens.


  8. Close the CopyShortcut database.


  9. Open Notepad and type the following:


  10. 
       Echo Off
       Start /wait /min CopyShortcut.mdb
       Cls
       Call Cleanup.bat 
  11. On the File menu, click Save As.


  12. Browse to the directory to where you saved CopyShortcut.mdb.


  13. Change the Save as Type box to All Files.


  14. In the File Name box, type Script.bat.

    NOTE: Script.bat is the file that will run at the end of your Setup package.


How to Create the Package

  1. Open the database or other file that will be the main file for your solution.


  2. Start the Package and Deployment Wizard.


  3. For additional information about loading the Package and Deployment Wizard, click the article number below to view the article in the Microsoft Knowledge Base:
    Q236143 MOD2000: How to Start the Package and Deployment Wizard
  4. Click Package and take the defaults if you want until you get to the screen called Package and Deployment Wizard - Included Files.


  5. If the target computers need Access to run your solution, check Include Access Runtime. When asked for the location of the runtime files, browse to your CD and go to the following path:


  6. \ODETools\V9\AccessRT
  7. Click Add, and add the files CopyShortcut.mdb and Script.bat to the Files list.


  8. Click Next. Select the Run this command when installation is finished check box, and type Script.bat.


  9. Click Next. You see the default shortcut for your solution. Notice that the group under Programs as well as the shortcut has the same name as the installation title you saw on an earlier screen in the wizard.

    NOTE: Make sure they are named the same as the path you specified when you modified the code of the DeskTopShortcuts module in step 2 of "How to Create CopyShortcut.mdb and Script.bat".


  10. At the Screen Package and Deployment Wizard - Install Locations screen, change the Install Locations of the two files you added earlier to the following:


  11. 
       CopyShortcut.mdb
       ----------------
       Install Location: $(WinPath)
    
       Script.bat
       ----------
       Install Location: $(WinPath) 
  12. Now follow the instructions from the Package and Deployment Wizard and finish building your solution.


When you run Setup from the package, a shortcut should be created on your desktop.

NOTE: The process described in this article only functions during the initial Setup of the solution. Running Setup in maintenance mode does not cause a shortcut to be created. If necessary, you should uninstall and then reinstall the run-time application.


REFERENCES

For more information about including executables to run at the end of a solution's Setup, open the MSDN Library, go to the Index tab, and type the following:

Package and Deployment Wizard-Installation Options

Additional query words: icon icons

Keywords : kbdta modPDWizard
Version : :
Platform :
Issue type : kbhowto


Last Reviewed: November 24, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.