Solved

Dynamic Creation of a Shortcut.

Posted on 1998-07-16
7
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

739 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