We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Dynamic Creation of a Shortcut.

nelchr
nelchr asked
on
Medium Priority
336 Views
Last Modified: 2010-05-03
Within VB5 code, can I create a shortcut file (.lnk)  to  a known .exe file?  If so, how?
Comment
Watch Question

Commented:
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


Author

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?
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
You can get a copy of the STKIT432.DLL file at the address listed below.
http://www.soft.net.uk/jazz/download.htm
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

Author

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.
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
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.