Results 1 to 15 of 15

Thread: Creating shortcuts of application

  1. #1

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Creating shortcuts of application

    Hi all,

    Is there anyway to make a shortcut of a program that will run like the original, but is on the desktop? I need to do this because my program relies on two text files that I have in App.Path, and If i put it on the desktop I will need to put the folders on the desktop too and that won't work.


    Does anyone know if this is possible?

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Creating shortcuts of application

    Select your program in Windows Explorer then right click and create shortcut. Move it to the desktop or create it to the desktop.

  3. #3
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Creating shortcuts of application

    VB Code:
    1. Private Declare Function fCreateShellLink Lib "VB5STKIT.DLL" _
    2.     (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, _
    3.     ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
    4.  
    5. dim lngRslt as long
    6.  
    7. lngRslt = fCreateShellLink("..\..\Desktop", ShortCutName, App.Path & "\exe.exe", (properties))

  4. #4

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Creating shortcuts of application

    Great thanks to both

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Creating shortcuts of application

    Here is what I use (written awhile ago) to create shortcurs on the desktop (you may need to add some logic to check if it altready exist but it isn't really necessary):
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function OSfCreateShellLink Lib "vb6stkit.dll" Alias "fCreateShellLink" _
    4.                         (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, _
    5.                          ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String, _
    6.                          ByVal fPrivate As Long, ByVal sParent As String) As Long
    7.  
    8. Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
    9.                         (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
    10.  
    11. Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
    12.                         (ByVal pidl As Long, ByVal pszPath As String) As Long
    13.  
    14. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
    15.  
    16. Private Const ERROR_SUCCESS = 0&
    17. Private Const CSIDL_DESKTOPDIRECTORY = &H10       '{user}\Desktop
    18.  
    19. Private Sub Form_Load()
    20. '============================
    21. Dim strLinkName As String
    22. Dim strFullPath As String
    23. Dim strComLineArgs As String
    24. Dim bPrivate As Boolean
    25. Dim strParent As String
    26.  
    27.     strLinkName = App.EXEName & ".exe"
    28.     strFullPath = App.Path & "\" & App.EXEName & ".exe"
    29.     strComLineArgs = ""
    30.     bPrivate = True
    31.     strParent = "$(Programs)"
    32.    
    33.     CreateShortcut strLinkName, strFullPath, strComLineArgs, bPrivate, strParent
    34.  
    35. End Sub
    36.  
    37. Private Sub CreateShortcut(strLinkName As String, _
    38.                            strFullPath As String, _
    39.                            strComLineArgs As String, _
    40.                            bPrivate As Boolean, _
    41.                            strParent As String)
    42. '======================================================
    43. Dim sDeskPath As String
    44. Dim Pos As Integer
    45. Dim strDestination As String
    46.  
    47. On Error Resume Next
    48.  
    49.     sDeskPath = GetSpecialFolder(Me.hwnd, CSIDL_DESKTOPDIRECTORY)
    50.     Pos = InStrRev(sDeskPath, "\")
    51.     strDestination = "..\.." & Mid(sDeskPath, Pos)
    52.    
    53.     OSfCreateShellLink strDestination, strLinkName, strFullPath, _
    54.                        strComLineArgs, bPrivate, strParent
    55.  
    56. End Sub
    57.  
    58. Public Function GetSpecialFolder(hwnd As Long, CSIDL As Long) As String
    59. '========================================================================
    60. Dim pidl As Long
    61. Dim Pos As Long
    62. Dim sPath As String
    63.      
    64.     'fill the pidl with the specified folder item
    65.     If SHGetSpecialFolderLocation(hwnd, CSIDL, pidl) = ERROR_SUCCESS Then
    66.         'initialize & get the path
    67.         sPath = Space$(260)
    68.         If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
    69.             'check for a null
    70.             Pos = InStr(sPath, Chr$(0))
    71.             If Pos Then 'strip it
    72.                 GetSpecialFolder = Left$(sPath, Pos - 1)
    73.             End If
    74.             Call CoTaskMemFree(pidl)
    75.         End If
    76.     End If
    77.    
    78. End Function

  6. #6

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Creating shortcuts of application

    One more question. How could I set all of the selected items in a file list box into an array? I tried this but only got the first item selected.

    VB Code:
    1. Private Sub cmdCopyTo_Click()
    2.     Dim i As Integer
    3.     If File1.ListIndex < 0 Then
    4.         MsgBox "No Selected Songs.", vbCritical
    5.         Exit Sub
    6.     End If
    7.     ReDim sFileName(File1.ListIndex - 1)
    8.     For i = 0 To UBound(sFileName)
    9.         sFileName(i) = File1.Path
    10.         If Right$(sFileName(i), 1) <> "\" Then
    11.             sFileName(i) = sFileName(i) & "\"
    12.         End If
    13.         sFileName(i) = sFileName(i) [COLOR=Red]& File1.Filename[/COLOR]
    14.     Next i
    15.     blnCopy = True
    16. End Sub

    I'm pretty sure that the part in red is what is wrong. But I can't figure out how to get the first, second, third, ect file name in the file list box

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Creating shortcuts of application

    Here is modified version (untested) so give it the try and let em know if works for you:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim i As Integer
    3.  
    4.     If File1.ListIndex < 0 Then
    5.         MsgBox "No Selected Songs.", vbCritical
    6.         Exit Sub
    7.     End If
    8.    
    9.     ReDim sFileName(0)
    10.     blnCopy = False
    11.    
    12.     For i = 0 To File1.ListCount - 1
    13.         If File1.Selected(i) = True Then
    14.             sFileName(UBound(sFileName)) = File1.List(i)
    15.             ReDim Preserve sFileName(UBound(sFileName) + 1)
    16.         End If
    17.     Next i
    18.     If UBound(sFileName) > 0 Then
    19.         If Trim(sFileName(UBound(sFileName))) = "" Then
    20.             ReDim Preserve sFileName(UBound(sFileName) - 1)
    21.         End If
    22.     End If
    23.     If Trim(sFileName(0)) <> "" Then
    24.         blnCopy = True 'not sure what this is for ???
    25.     End If
    26.  
    27. End Sub

  8. #8
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Creating shortcuts of application

    Use
    VB Code:
    1. For i = 0 To File1.ListIndex - 1
    2.  
    3. and
    4.  
    5. If File1.Item(i).Selected Then

  9. #9

  10. #10
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Creating shortcuts of application

    Youre right I did not look properly at the portion of the line I copied from the original code. I assumed he had it right... Incorrectly I add

  11. #11

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Creating shortcuts of application

    Quote Originally Posted by RhinoBull
    Here is modified version (untested) so give it the try and let em know if works for you:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim i As Integer
    3.  
    4.     If File1.ListIndex < 0 Then
    5.         MsgBox "No Selected Songs.", vbCritical
    6.         Exit Sub
    7.     End If
    8.    
    9.     ReDim sFileName(0)
    10.     blnCopy = False
    11.    
    12.     For i = 0 To File1.ListCount - 1
    13.         If File1.Selected(i) = True Then
    14.             sFileName(UBound(sFileName)) = File1.List(i)
    15.             ReDim Preserve sFileName(UBound(sFileName) + 1)
    16.         End If
    17.     Next i
    18.     If UBound(sFileName) > 0 Then
    19.         If Trim(sFileName(UBound(sFileName))) = "" Then
    20.             ReDim Preserve sFileName(UBound(sFileName) - 1)
    21.         End If
    22.     End If
    23.     If Trim(sFileName(0)) <> "" Then
    24.         blnCopy = True 'not sure what this is for ???
    25.     End If
    26.  
    27. End Sub
    Ok, I should have just asked this to, but I need the directory of the file list box infront of the names.

  12. #12

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Creating shortcuts of application

    Ok, sorry I have so many questions on one thread, but how come I have no "FileSystemObject" in my references?

    I'm trying to use this code

    VB Code:
    1. 'Set A Reference To FileSystemObject
    2.  
    3. Private Function FileCount(ByVal FolderName As String) As Long
    4. Dim objFS As New Scripting.FileSystemObject
    5. Dim objFolder As Scripting.Folder
    6.  
    7. If objFS.FolderExists(FolderName) Then
    8.     Set objFolder = objFS.GetFolder(FolderName)
    9.     'if this lines returns more than 0, the folder has files
    10.     FileCount = objFolder.Files.Count
    11. End If
    12.  
    13. Set objFolder = Nothing
    14. Set objFS = Nothing
    15.  
    16. End Function
    17.  
    18. Private Sub cmdCheckForFiles_Click()
    19. MsgBox FileCount("C:\windows\system")
    20. End Sub
    Attached Images Attached Images  

  13. #13

  14. #14
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Creating shortcuts of application

    Look for Microsoft Scripting Runtime in components.

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Creating shortcuts of application

    Quote Originally Posted by dglienna
    Look for Microsoft Scripting Runtime in components.
    Actually, it is a reference.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width