• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

Dynamic Creation of a Shortcut.

Within VB5 code, can I create a shortcut file (.lnk)  to  a known .exe file?  If so, how?
0
nelchr
Asked:
nelchr
  • 3
  • 2
  • 2
1 Solution
 
movieguyCommented:
This assumes you are running NT and you would like to create a shortcut on the desktop to a program.  If you want the shortcut else where just change the path infomation.

This was found in the following article
http://support.microsoft.com/support/kb/articles/q155/3/03.asp

Steps for Creating a Shell Link (Shortcut) to the Desktop

Start a new project in Visual Basic. Form1 is created by default.

Add a Command button (Command1) to Form1.

Add the following code to the General Declarations section of Form1:
Option Explicit



      Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal _
        lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal _
        lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long

      Sub Command1_Click()

        Dim lReturn As Long

        'Add to Desktop
        lReturn = fCreateShellLink("..\..\Desktop", _
        "Shortcut to Calculator", "c:\Winnt\system32\calc.exe", "")

        'Add to Program Menu Group
        lReturn = fCreateShellLink("", "Shortcut to Calculator", _
        "c:\Winnt\system32\calc.exe", "")

        'Add to Startup Group
        lReturn = fCreateShellLink("\Startup", "Shortcut to Calculator", _
        "c:\Winnt\system32\calc.exe", "")

      End Sub


0
 
nelchrAuthor Commented:
You've got the right idea about what I want.  However, I cannot find the .dll file you referenced.  Where does STKIT432.DLL come from?
0
 
ImmanuelOnseCommented:
Soln: refer VB 5 CD in \Tools\Unsupprt\ShellLnk

Further:
I'm writing a program which starts at a given dir & then modifies shortcuts in subdirs down the tree. If a shortcut refers to K:\MSOFFICE it is modified to C:\Program Files\MSOffice, otherwise shortcuts are left alone.

The MICROSOFT way to do this is through OLE. Refer: MSDN CD2 - Chapter 9 of "Programming the W95 User Interface".

I have found references to "STKIT432.DLL", "shlobj" & in particular MS
      KB articles (C code)
      Q130698 How to: obtain filename & path from a shell link or shortcut
      Q179904 How to: change the icon of a shortcut through IShellLink
      Q155303 How to: create shortcuts (shell links) within windows
      Q140443 How to: create a  shortcut on the desktop

While hunting references over at Carl & Gary's VB page I found an excerpt from comp.lang.basic.visual.misc "Re: Creating .lnk and .pif files" posted by MDT. It mentioned the example on the VB 5 CD in \Tools\Unsupprt\ShellLnk This example, & TestSLnk within it, do everything needed for creating & modifying shortcuts

I now have this program up and running. The only problem I had with the example from MS was, if a Shortcut refers to a file which Windows can't find/resolve (ie it's on a Network drive that's not currently linked) then it displays a dialog box "Missing Shortcut". I have hacked a fix to this which suppresses this dialog box and am chasing up a better way to do it.

Visit my Home page if you wish to get the code, "http://www.pcug.org.au/~shorvat", I'll post it there over the next 24 hours
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
movieguyCommented:
You can get a copy of the STKIT432.DLL file at the address listed below.
http://www.soft.net.uk/jazz/download.htm
0
 
ImmanuelOnseCommented:
I have placed a copy of my executable program & source code at
http://www.tip.net.au/~shorvat/lnk_mod/

As stated before, it is based on the example on the VB 5 CD (Enterprise Edition) in \Tools\Unsupprt\ShellLnk

The program is not finished, but the feature to read & modify shortuts under W95 is finished. The core of this is in LnkFcns.bas & ShellLnk.dll

To create shortcuts from scratch, just add entry fields for IconIdx & ShowCmd
0
 
nelchrAuthor Commented:
OK.
Now I have two versions:  Movieguy - Thanks for the code.  Nice and simple.
ImmanuelOnse - Thanks for the OOP method.  
By accepting this response only ImmanuelOnse will get points.  Not my intention.  I am new to this exchange.  Is there a way to give points to both of you?  If not, my apologies to Movieguy.
0
 
ImmanuelOnseCommented:
Yes, Post a Q titled "For Movieguy" & in it refer to problem Q.10064350
Movieguy can post an empty answer
When you accept his answer the points you set will be assigned to him

If a newbie expert accidentally posts an answer before Movieguy then just re-open the problem until Movieguy answers you
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now