Solved

VB6 Problem Creating Shortcut in Startup Folder

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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 …
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.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

803 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