Link to home
Start Free TrialLog in
Avatar of Vignette
Vignette

asked on

Changing path of desktop shortcuts

Hi have a ap that write an exe to the desktop of the client.

I am ugrading the app and the name of the folder were the exe is sitting is changing.How do i write some code that will change the path of the exe shortcut to point to the exe in the renamed folder.

Before I was just adding a shortcut like this

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 AddDesktopIcons()
Dim strGroupName As String, strLinkName As String
Dim strLinkPath As String, strLinkArguments As String
Dim fPrivate As Boolean, sParent As String
Dim fSuccess As Boolean

strLinkName = "Shortcut to WordGenerator"
 strLinkPath = "c:\Program Files\PWM AP Document Generator\WordGenerator.exe"
 strLinkArguments = ""
 fPrivate = True                              ' Add shortcut to desktop.
strGroupName = "..\..\Desktop"
sParent = "$(Programs)"
fSuccess = fCreateShellLink(strGroupName & vbNullChar, strLinkName, strLinkPath, strLinkArguments & vbNullChar, fPrivate, sParent)

End sub
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MrRoper
MrRoper

Have a play with the windows script host COM




In VB Menu->Project->References add: Windows Script Host Object Model

 

Private Sub TryMe()

    Dim WShell As WshShell

    Dim Shortcut As WshShortcut

   

    Set WShell = New WshShell

    'Note: Displayed name = np

    Set Shortcut = WShell.CreateShortcut("c:\windows\desktop\np.lnk")

   

    Shortcut.TargetPath = "c:\windows\notepad.exe"

    Shortcut.Save



    Set Shortcut = Nothing

    Set WShell = Nothing

End Sub


MrRoper, that works just as well, though as it is effectively a wrapper for the same API functions it also will change an existing shortcut if and only if you are using the SAME shortcut name.
Avatar of Vignette

ASKER

works great thanks

cant believe i missed that
You appear to have posted a duplicate of this question at https://www.experts-exchange.com/questions/20326755/Changing-path-of-desktop-shortcuts.html it would be best to delete this asap.
I am trying but cant find where you delete it