How to place a shortcut for my .exe in the desktop automatically ,when user runs the setup program ?. ( The setup program created by using application setup wizard vb 5.0 is not creating the shortcut in the desktop.)
Who is Participating?
johnny6Connect With a Mentor Commented:
      Here is another way to do it:

'create a shortcut to a file and place it on desktop
Option Explicit
Private Declare Function SHGetSpecialFolderLocation Lib _
"Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, _
ppidl As Long) As Long

Private Declare Function SHGetPathFromIDList Lib "Shell32" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath _
As String) As Long

Private Const MAX_PATH = 260

Public Function GetDesktopFolderPath(ByVal pHwnd As Long) _
As String

Dim lReturn&
Dim lPidl&
Dim strPath$
strPath$ = Space(MAX_PATH)
lReturn& = SHGetSpecialFolderLocation(pHwnd, 0, lPidl)

' Get lPidl& for this Id...
If lReturn = 0 Then
lReturn = SHGetPathFromIDList(lPidl, strPath)
' Get Path from Item Id List
If lReturn = 1 Then 'If successeful
GetDesktopFolderPath = Left(strPath$, _
InStr(strPath$, vbNullChar) - 1)

End If
End If
End Function
'====================put this in form load =======================
Dim strDesktop$
strDesktop = GetDesktopFolderPath(Me.hWnd)
Dim strMyfile$
strMyfile = InputBox("Enter the path and name of file, & vbcrlf" _
& "you want to create a shortcut for.")
Dim strShortCutName$
strShortCutName$ = InputBox _
("Enter the name for the shortcut icon")

FileCopy strMyfile$, strDesktop$ & "\" & strShortCutName$

     Determine which one suits you best: 
or Start a new project in Visual Basic. Form1 is created by default.
Add a Command button (Command1) to Form1.
Add the following code to the General Declarations section of Form1:

Option Explicit
'NOTE: In Visual Basic 5.0, change Stkit432.dll in the following
'statement to Vb5stkit.dll.

Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal _
lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal _
lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long

Sub Command1_Click()
Dim lReturn As Long
'Add to Desktop
lReturn = fCreateShellLink("..\..\Desktop", _
"Shortcut to Calculator", "c:\Winnt\system32\calc.exe", "")
'Add to Program Menu Group
lReturn = fCreateShellLink("", "Shortcut to Calculator", _
"c:\Winnt\system32\calc.exe", "")
'Add to Startup Group
'Note that on Windows NT, the shortcut will not actually appear
'in the Startup group until your next reboot.
lReturn = fCreateShellLink("\Startup", "Shortcut to Calculator", _
"c:\Winnt\system32\calc.exe", "")
End Sub

Press the F5 key to run the project, and then click the Command button.


iqubalAuthor Commented:
Thank you for the answer Mr. John.
But I was thinking that there must a provision in the setup.lst file which is generated by the Seup Wizard. If there is any way like that Please intimate me.
Thanks again

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.