?
Solved

Startup Shortcut

Posted on 1999-12-05
15
Medium Priority
?
823 Views
Last Modified: 2012-05-04
Hey Guys, I am trying to create and delete a startup shortcut within my VB6 program.  I have these functions:

Declare Function OSfCreateShellLink Lib "vb6stkit.dll" Alias "fCreateShellLink" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String, ByVal fPrivate As Long, ByVal sParent As String) As Long

Declare Function OSfRemoveShellLink Lib "vb6stkit.dll" Alias "fRemoveShellLink" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String) As Long

but I can't figure out what to pass them in order to get them to work.  I tried to use the same parameters I used for my VB5 project but that dosn't work.  Also, do these functions work under Windows NT 4.0? Win 2K?

Thanks for any help.
0
Comment
Question by:Ra
15 Comments
 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 2257223
do you mean during installation ?
0
 

Author Comment

by:Ra
ID: 2257407
No.  This is an option the user will be able to change during operation of the program.
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 2258288
try to change the properties of the shortcut


it is a file too
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 14

Expert Comment

by:mcrider
ID: 2258347
Check out this microsoft article:

HOWTO: Create Shortcuts (Shell Links) within Windows
http://support.microsoft.com/support/kb/articles/Q155/3/03.asp 
 

Cheers!
0
 

Author Comment

by:Ra
ID: 2260747
morider, that works for 4 and 5, but I was wanting to know how to use it in VB 6.  If you look at the functions above, you will see that the parameters are different and passing the same stuff you would in VB 5 does not work.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2260855
OK, Try this:

Private Declare Function OSfCreateShellLink Lib "vb6stkit.dll" Alias "fCreateShellLink" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String, ByVal fPrivate As Long, ByVal sParent As String) As Long
Private Sub Command1_Click()
Dim strGroupName As String
Dim strLinkName As String
Dim strLinkPath As String
Dim strLinkArguments As String
Dim fPrivate As Long
Dim sParent As String
Dim Retcode As Long

strGroupName = "C:\WINDOWS\DESKTOP" 'DIRECTORY TO USE AS GROUP NAME
strLinkName = "Shortut to WordTime" 'TITLE OF SHORTCUT
strLinkPath = "D:\UTILITIES\WORDTIME.COM" + Chr$(0) 'PATH OF REAL FILE
strLinkArguments = Chr$(0) 'KEEP THIS AS IS
fPrivate = -1 'KEEP THIS AS IS
sParent = "C:\WINDOWS\DESKTOP" 'DIRECTORY WHERE SHORTCUT IS CREATED

Retcode = OSfCreateShellLink(strGroupName, strLinkName, strLinkPath, strLinkArguments, fPrivate, sParent)
MsgBox Retcode
End Sub


Cheers!

0
 

Author Comment

by:Ra
ID: 2263967
I hate to tell you this, but no matter what I do it returns a code of 0.  I copied it into my project and modified the group, title, and directories to fit my project.  I also copied the code exactly into a new porject and it dosn't work there either.

I also want to put the shortcut in the current users startup folder in his start menu.  How do I do that?

Since I didn't make that part clear in my original question, thereby making the question harder, I'm increasing the points to 100.
0
 

Author Comment

by:Ra
ID: 2263973
BTW, I forgot to mention that I already have code to find the Windows or WinNT directory that works great.  (The GetWindowsDirectory function)  I just need to kwon the person's usernam.

Thanks.
0
 
LVL 14

Accepted Solution

by:
mcrider earned 200 total points
ID: 2264006
Don't know what to tell you... I was able to use the code above to create a shortcut on my desktop using the vb6stkit.dll

I guess you'll have to wait for someone else...

Cheers!
0
 
LVL 5

Expert Comment

by:dtomyn
ID: 2293990
I personally have been using code similar to what is found at: http://www.mvps.org/vbnet/code/shell/shshortcutcheat.htm 
Alternatively, you can try:
http://www.mvps.org/vbnet/code/shell/desktoplink.htm
0
 

Author Comment

by:Ra
ID: 2294068
Nevermind guys, I just decied to go back and use the vb5.0 version.  It works fine.  Since mcrider gave me the best help, even though it didn't work on my system (I think I have something screwy preventing it from working), I am gonna give him the points (but he only gets a 'C').


*****
If you are looking for the details, scroll down to you see a lot of code with his name at the top.  It's under a rejected answer bar, but I couldn't find a way to unreject it or delete the quesiton.  My only option was to accept one of his comments as the answer.
*****

Thanks for trying guys.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2295309
Thanks for the points...

By the way, I have VB5, but I installed the vb6stkit.dll on my system and that code worked fine...


Cheers!
0
 

Author Comment

by:Ra
ID: 2296365
I probably just need to reinstall 6.0.  I download a lot of shareware programs and who knows what dlls have been replaced.
0
 
LVL 1

Expert Comment

by:csameer1
ID: 2831982
Here is how you would add this to your setup script.You will need to edit the setup project (C:\Program Files\Microsoft Visual Studio\VB98\Wizards\PDWizard\Setup1) and add the code below after appropriate user responses.Make sure you make a copy of the setup project supplied by microsoft.
________________________________________


Private Declare Function fCreateShellLink Lib "vb6stkit.dll" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String, ByVal fPrivate As Long, ByVal sParent As String) As Long
Private Sub Command1_Click()

    Dim strGroupName As String
    Dim strLinkName As String
    Dim strLinkPath As String
    Dim strLinkArguments As String
    Dim fPrivate As Long
    Dim sParent As String

    strLinkPath = App.Path + "\" + App.EXEName + Chr(0)
    strLinkName = "Shortcut to " + App.EXEName
    strLinkArguments = "" + Chr(0)
    fPrivate = -1
    strGroupName = "..\..\start menu\programs\startup" 'for a desktop scut use "..\..\desktop"
    sParent = "$(Programs)"

    fCreateShellLink strGroupName, strLinkName, strLinkPath, strLinkArguments, fPrivate, sParent

End Sub

0
 

Author Comment

by:Ra
ID: 2833645
Kewl!!! It works!  Thanks, casameer1.  I wish there was a way I could give you the points, but there is no way to un-accept the accepted answer, sorry.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

600 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