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
Solved

VB6 Problem Creating Shortcut in Startup Folder

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

828 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