-
Ok, so I have this code to create a shortcut:
Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
'Usage:
fCreateShellLink "C:\windows\Desktop", "Link to my program", "C:\Path\Program.exe", ""
Now, I want the program to create the shortcut when I run the setup. How do I do that? Tell me NOW!!!!
-
Code:
Public Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String) As Long
Public Sub makeshortcut(strshortcutdir As String, strshortcutname As String, strshortcutpath As String)
On Error Resume Next
Dim strwinshortcutdir As String, strwinshortcutname As String, strwinshortcutexepath As String, lngretval As Long
Let strwinshortcutdir$ = strshortcutdir$
Let strwinshortcutname$ = strshortcutname$
Let strwinshortcutexepath$ = strshortcutpath$
Let lngretval& = fCreateShellLink("", strwinshortcutname$, strwinshortcutexepath$, "")
Name "c:\windows\start menu\programs\" & strwinshortcutname$ & ".lnk" As strwinshortcutdir$ & "\" & strwinshortcutname$ & ".lnk"
End Sub
Call makeshortcut("C:\Windows\Start Menu\Programs\Startup\","MyProgram","C:\apps\program.exe")
-
But I'm saying though, where do I call the function? If I call it during a form load, won't it make the shortcut every time I run the program or load the form?
-
If dir(strshortcutdir)="" then makeshorcut...
-
Code:
Public Function fileexists(strfilepathandname As String) As Boolean
On Error Resume Next
Dim lngcheck As Long
If InStr(strfilepathandname$, ".") = 0& Then
Let fileexists = False
End If
Let lngcheck& = Len(Dir$(strfilepathandname$))
If lngcheck& = 0& Then
Let fileexists = False
Exit Function
Else
Let fileexists = True
End If
Exit Function
End Function
If not fileexists("C:\Windows\Start Menu\Programs\Startup\program.lnk") Then Call makeshortcut("C:\Windows\Start Menu\Programs\Startup\","MyProgram","C:\apps\program.exe")
-
Mathew, why do you use Let? also it's a lot code for checking a file existance, why do you need the "." to be in the filè?
-
Thanks for all your help. I'll have to mess around with this a little bit.
-
I dunno Kedaman..it's just a code I use. I feel comfortable with it. It works, doesn't it? As long as it works, its good. But I guess your way is a shorter way.
-
Well Let is a obsolete keyword, "." don't exist in all files, but you might return a file of you mention a dir.
Yeah it works but dir(path)<>"" is a much shorter and faster way
-
BTW, I tried both today and neither works in my program.
I called the Function from a form load... I dunno' but I think I'm just gonna create a shortcut and distribute separately... thanks anywayz