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
-
In Access, create a new database called CopyShortcut.mdb.
-
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.
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
-
Save the new module as DeskTopShortcuts.
-
Create the following new macro and name it AutoExec:
Action
------
RunCode
Action Arguments
-------------------------------
Function Name: CopyAppShortCut()
-
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.
-
Close the CopyShortcut database.
-
Open Notepad and type the following:
Echo Off
Start /wait /min CopyShortcut.mdb
Cls
Call Cleanup.bat
-
On the File menu, click Save As.
-
Browse to the directory to where you saved CopyShortcut.mdb.
-
Change the Save as Type box to All Files.
-
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
-
Open the database or other file that will be the main file for your solution.
-
Start the Package and Deployment Wizard.
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
-
Click Package and take the defaults if you want until you get to the screen called Package and Deployment Wizard - Included Files.
-
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:
\ODETools\V9\AccessRT
-
Click Add, and add the files CopyShortcut.mdb and Script.bat to the Files list.
-
Click Next. Select the Run this command when installation is finished check box, and type Script.bat.
-
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".
-
At the Screen Package and Deployment Wizard - Install Locations screen, change the Install Locations of the two files you added earlier to the following:
CopyShortcut.mdb
----------------
Install Location: $(WinPath)
Script.bat
----------
Install Location: $(WinPath)
-
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
|