Solved

VB6 Problem Creating Shortcut in Startup Folder

Posted on 2008-10-28
3
870 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now