Solved

Creating Desktop Shortcut "Opens With" property

Posted on 2007-11-19
2
395 Views
Last Modified: 2013-11-29
I currently create shortcuts on users desktops using the below.
Dim myWSH As Object
Dim WSHShortcut As Object
'If Len(Dir("C:\Documents and Settings\All Users\Desktop\OpsTools.lnk", vbDirectory)) = 0 Then 'Adding a Shortcut to their Desktop if it doesn't already exist
'------------------
Set myWSH = CreateObject("WScript.Shell")
Set WSHShortcut = myWSH.CreateShortcut("C:\Documents and Settings\All Users\Desktop\Myshortcut.lnk")
    With WSHShortcut
        .TargetPath = "MyTarget"
        .Description = "Shortcut to My shortcut"
        .IconLocation = "MyiconDirFile"
        .RelativePath = "c:\temp"
        .WorkingDirectory = "C:\"
        .WindowStyle = 7   ' 1 = normal; 3 = maximize window; 7 = minimize
        .Hotkey = "Ctrl+Alt+Q"
        .Save
    End With
    Set myWSH = Nothing
    Set WSHShortcut = Nothing
'----------------------
I also need to specify the "Opens With" property to ensure that this files always opens with Access 2000 and not 97. Any ideas. I see that you can do it when you right click the icon, so I'm sure there is a way that I can do it when creating the shortcut...
0
Comment
Question by:a260148
2 Comments
 
LVL 27

Accepted Solution

by:
VBRocks earned 500 total points
ID: 20315285
You can do it by putting the path to the executable before the path to the database.  However, if you
have different installs of Access, then you will need to get the path from the registry first:

Set myWSH = CreateObject("WScript.Shell")

Dim path As String
path = myWSH.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Office\9.0\Access\InstallRoot\Path")
path = path & "MSACCESS.EXE"

Dim databasePath As String
databasePath = "C:\TEMP\db4.mdb"

Set WSHShortcut = myWSH.CreateShortcut("C:\Documents and Settings\All Users\Desktop\Myshortcut.lnk")
    With WSHShortcut
        .TargetPath = Chr(34) & path & Chr(34) & " " & Chr(34) & databasePath & Chr(34)
        .Description = "Shortcut to My shortcut"
        .IconLocation = "MyiconDirFile"
        .RelativePath = databasePath
        .WorkingDirectory = "C:\"
        .WindowStyle = 3 '7   ' 1 = normal; 3 = maximize window; 7 = minimize
        .Hotkey = "Ctrl+Alt+Q"
        .Save
    End With
   
    Set myWSH = Nothing
    Set WSHShortcut = Nothing

0
 

Author Closing Comment

by:a260148
ID: 31409972
Great. Thanks
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question