Solved

Dynamic Creation of a Shortcut.

Posted on 1998-07-16
7
269 Views
Last Modified: 2010-05-03
Within VB5 code, can I create a shortcut file (.lnk)  to  a known .exe file?  If so, how?
0
Comment
Question by:nelchr
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Expert Comment

by:movieguy
ID: 1466024
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
 

Author Comment

by:nelchr
ID: 1466025
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
 

Accepted Solution

by:
ImmanuelOnse earned 50 total points
ID: 1466026
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Expert Comment

by:movieguy
ID: 1466027
You can get a copy of the STKIT432.DLL file at the address listed below.
http://www.soft.net.uk/jazz/download.htm
0
 

Expert Comment

by:ImmanuelOnse
ID: 1466028
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
 

Author Comment

by:nelchr
ID: 1466029
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
 

Expert Comment

by:ImmanuelOnse
ID: 1466030
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 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

18 Experts available now in Live!

Get 1:1 Help Now