Solved

Creating Desktop Shortcut "Opens With" property

Posted on 2007-11-19
2
411 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

734 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