Solved

VB6 Problem Creating Shortcut in Startup Folder

Posted on 2008-10-28
3
882 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
[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
  • 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

Independent Software Vendors: 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

705 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