Solved

VB6 Problem Creating Shortcut in Startup Folder

Posted on 2008-10-28
3
878 Views
Last Modified: 2012-08-14
Using the attached code, I am able to create and delete a shortcut to my program in the startup folder.

However, once created and deleted, the shortcut cannot be created again until the program is closed, then opened again. What is my mistake?

Thanks!
If mnuStartWithWindows.Checked = False Then
    'Add to Startup Group
    mnuStartWithWindows.Checked = True
    fCreateShellLink StartupFolder, "My Program", App.Path + "\My Program", "" & vbNullChar, -1, StartupFolder
Else
    'Remove from Startup Group
    mnuStartWithWindows.Checked = False
    If fso.FileExists(StartupFolder + "\My Program.lnk") Then
      fso.DeleteFile StartupFolder + "\My Program.lnk"
    End If
End If

Open in new window

0
Comment
Question by:ttobin333
  • 2
3 Comments
 
LVL 18

Expert Comment

by:mdougan
ID: 22831482
Can you show us the code for this routine?

fCreateShellLink
0
 

Author Comment

by:ttobin333
ID: 22832354
It's just a declaration of the function:

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

Thanks.
0
 
LVL 18

Accepted Solution

by:
mdougan earned 500 total points
ID: 22832753
Humm... the problem is likely in the DLL.  DLL's are loaded into memory when you first call them, then typically stay loaded until the program is closed.  If you are having problems the second time you call the function for the same link (does it only happen if you re-use the exact same link name, or anytime you call it twice to create two links?) , then it sounds like it isn't releasing a lock on a resource or something (like not closing the file when it exits the function).

If that is the case, the only thing I can think of, is that it is possible to manually unload a DLL from memory.  But I'm drawing a blank on the Windows API call to do that.  I remember that it was sort of complicated to do.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

733 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