ODE: How to Create a Shortcut on the Desktop with ODE

ID: Q182606


The information in this article applies to:

Advanced: Requires expert coding, interoperability, and multiuser skills.


SUMMARY

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.


MORE INFORMATION

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

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

The following steps demonstrate how to create the additional files discussed above and how to distribute them with the sample Northwind (Northwind.mdb) database using the Microsoft Office Developer Edition Tools Setup Wizard.

Creating CopyShortcut.mdb and Script.bat

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


  2. Create the following new module:


  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"
    
              ' 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 
  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 any text editor (such as Notepad) and type the following:


  10. Echo Off
    Start /wait /min CopyShortcut.mdb
    Cls
    Call Cleanup.bat
  11. Save the new text file as Script.bat.


Creating a Run-Time Distribution



  1. Run the Microsoft Office 97 Developers Edition Tools Setup Wizard.


  2. Select "Create a new set of setup options for my application's custom Setup Program", and then click Next.


  3. Add the following files to the List Of Files window. Make sure to correctly set File Properties for each file you add.
    
           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.


  4. Click Add to include a shortcut to run Northwind.mdb:
    
           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.


  5. Make sure the following components are being included in your run-time distribution, and then click Next twice to bypass the next screen.


  6. 
           Microsoft Access Run-Time Version
           Workgroup Administrator 
  7. Name the application Northwind, and then click Next.


  8. In the "Run the following file after the custom Setup program is completed:" box, select Script.bat.


  9. In "Enter or edit the command line that will be used to run the executable file," type the following:


  10. "$(FilePath)\Script.bat"
  11. Select "Allow Setup to Complete Before the File Finishes Running," then click Next.


  12. Follow instructions from the Setup Wizard and complete building your run-time distribution.


When you run setup from either Disk 1 of your disk set or the "Net" Network/CD setup folder, a shortcut should be created on your desktop.

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


REFERENCES

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