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.ex e"
strLinkArguments = ""
fPrivate = True ' Add shortcut to desktop.
strGroupName = "..\..\Desktop"
sParent = "$(Programs)"
fSuccess = fCreateShellLink(strGroupN ame & vbNullChar, strLinkName, strLinkPath, strLinkArguments & vbNullChar, fPrivate, sParent)
End sub
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.ex
strLinkArguments = ""
fPrivate = True ' Add shortcut to desktop.
strGroupName = "..\..\Desktop"
sParent = "$(Programs)"
fSuccess = fCreateShellLink(strGroupN
End sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
works great thanks
cant believe i missed that
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.
ASKER
I am trying but cant find where you delete it
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:\
Shortcut.TargetPath = "c:\windows\notepad.exe"
Shortcut.Save
Set Shortcut = Nothing
Set WShell = Nothing
End Sub