Help and Support
 

powered byLive Search

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

Article ID:182606
Last Review:October 11, 2006
Revision:4.2
This article was previously published under Q182606
Advanced: Requires expert coding, interoperability, and multiuser skills.


On This Page

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.

Back to the top

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.
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.

Back to the top

Creating CopyShortcut.mdb and Script.bat

1.In Microsoft Access 97, create a new database called CopyShortcut.mdb.
2.Create the following new module:
       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
					
3.Save the new module as DeskTopShortcuts.
4.Create the following new macro and name it AutoExec:
       Action
       ------
       RunCode

       Action Arguments
       -------------------------------
       Function Name: CopyAppShortCut()
					
5.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.
6.Close the CopyShortcut database.
7.Open any text editor (such as Notepad) and type the following:
Echo Off
Start /wait /min CopyShortcut.mdb
Cls
Call Cleanup.bat
8.Save the new text file as Script.bat.

Back to the top

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.
       Microsoft Access Run-Time Version
       Workgroup Administrator
					
6.Name the application Northwind, and then click Next.
7.In the "Run the following file after the custom Setup program is completed:" box, select Script.bat.
8.In "Enter or edit the command line that will be used to run the executable file," type the following:
"$(FilePath)\Script.bat"
9.Select "Allow Setup to Complete Before the File Finishes Running," then click Next.
10.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.

Back to the top

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:
163062 (http://support.microsoft.com/kb/163062/EN-US/) ODE97: Errors Executing File After Custom Setup

Back to the top


APPLIES TO
Microsoft Office 97 Developer Edition

Back to the top

Keywords: 
kbhowto KB182606

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.