Solved

Dynamic Creation of a Shortcut.

Posted on 1998-07-16
7
277 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

831 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