Solved

Creating Desktop Shortcut "Opens With" property

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now