Solved

Creating Desktop Shortcut "Opens With" property

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

735 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