Solved

Creating Desktop Shortcut "Opens With" property

Posted on 2007-11-19
2
422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

623 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