Archive: At un-install remove renamed left over shortcuts best method?


At un-install remove renamed left over shortcuts best method?
SUBJECT:
At un-install remove renamed left over shortcuts best method?

ISSUE:
If an NSIS installer installs an application, it is easy at un-install to remove a known by name shortcut. However is the shortcut is renamed by a users the .lnk name changed and the un-install of the shortcut will not be performed.

WISH:
Like to have for a un-install improvement:

Look for shortcut and recursively delete shortcuts from a known application name e.g. "MYAPP.EXE"
- All users Startmenu
- All users Desktop
- Current user Startmenu
- Current users Desktop

* NSIS function that performs and looks like the following:

$0 = set Target to look for e.g. "MYAPP.EXE"
$1 = $SM value via NSIS or $DESKTOP values via NSIS
$2 = Current user or all users

...

Function un.removeleftovershortcuts $0 $1 $2

;PSEUDOCODE:
;; Look for shortcut and recursively delete shortcuts
; compare lastpart .lnk target with \+$0 with first stripping part after $0
; if same then this is a shortcut to delete

; If found delete Shortcut via dialogbox ask Delete? Y/N
; If silent install always delete/ nverdelete via a set boolean
; Refresh desktop if needed

; REAL CODE HERE PLZ :up:

FunctionEnd

...

I searched the Wiki but found no solution, maybe combine and adjust a lot of codesnippets from:
http://nsis.sourceforge.net/Category...File_Functions

But which are the best to start with? :confused:

QUESTION:
Anyone already once created such a script, be so kind as to share.

Somehow I have the feeling the "Locate" NSIS Script
http://nsis.sourceforge.net/Locate
could solve my problem but somehow cannot figure it out... maybe I should add sleep to the code ? ;)

TIA


To difficult? >:-)


Hi onad,
Just some thought, have no idea if could be done.
A method with system plugin that retrieves the target property from shortcuts in combination with locate plugin. E.g. Get shortcuts from desktop one by one with locate, pass each one to system plugin to retrieve the target, compare the retrieved target with a defined string, and remove every shortcut that has target myApp.exe.
Another thought, some kind of modification on MoreInfo plugin to be able ro retrieve the target property, again in combination with locate plugin.


The ShellLink plug-in allows you to retrieve the properties of shortcuts. You could scan through all shortcuts and compare their target to your target.


Thanks to kichik (always :-)) here is something:

OutFile "locate_shellink.exe"
ShowInstDetails show

!include "FileFunc.nsh"
!insertmacro Locate

!define MyApp "$PROGRAMFILES\Mozilla Firefox\firefox.exe"

Section
SetShellVarContext all
StrCpy $R0 ''

${Locate} "$DESKTOP" "/L=F /M=*.lnk /S=0B" "LocateCallback"

IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
MessageBox MB_OK "$$R0={$R0}"
SectionEnd


Function LocateCallback
ShellLink::GetShortCutTarget "$R9"
Pop $0

StrCmp '$0' '${MyApp}' 0 end
StrCpy "$R0" "$R9"
StrCpy "$0" StopLocate

end:
Push "$0"
FunctionEnd

Just tried another instance, uses RecFind.nsh and I think it is more accurate.
Besides it removes repeated wrong name shortcuts in a snap.

# Execute compiled installer then manual create some copies of the generated
# shortcut on desktop, then execute uninstaller and watch the action.
OutFile "RecFind_shellink.exe"
InstallDir '$EXEDIR'
ShowInstDetails show
ShowUninstDetails show

!include 'RecFind.nsh'

!define ICON_SEARCH '$DESKTOP\$R0\$R1'
!define MyApp '$1\nsis.exe'
!define Uninst 'unshortcut.exe'

Section Install
; SetShellVarContext all
ReadRegStr "$1" HKLM "Software\NSIS" ""
createshortcut '$DESKTOP\nsis.lnk' '${MyApp}'
ShellLink::SetShortCutWorkingDirectory '$DESKTOP\nsis.lnk' '$1'
Pop $0
messagebox mb_ok 'errorlevel $0'
writeuninstaller '$INSTDIR\${Uninst}'
sectionend

Section Uninstall
; SetShellVarContext all
ReadRegStr "$1" HKLM "Software\NSIS" ""
Delete '$DESKTOP\nsis.lnk'
${RecFindOpen} '$DESKTOP' '$R0' '$R1'
${RecFindFirst}
; DetailPrint '${ICON_SEARCH}'
ShellLink::GetShortCutTarget '${ICON_SEARCH}'
Pop $0
StrCmp '$0' '${MyApp}' 0 end
messagebox mb_ok '${ICON_SEARCH}'
Delete '${ICON_SEARCH}'
end:
${RecFindNext}
${RecFindClose}
Delete '$INSTDIR\${Uninst}'
SectionEnd

Great! Thanks Red Wine and Kichik,

I will try the solutions and see if they fit in my full goal.

Note that I still did not took an extra nap ;) since I was a really busy creating a plugin to solve the problem. I think I still will finish that plugin and post it to a Wikipage anyhow.

I also discovered that I did something wrong resolving the shortcuttarget and storing the value :((, so that is why shelllink and locate combination did not work at all during my tryouts...


Tried it, and the second solution really works good and fast almost without enlarging the intaller size, thanks!

No need for yet another plugin ;)


Well, I got a step deeper.
Following example removes normal/renamed shortcut(s) from desktop and also removes normal/renamed shortcus from Start Menu along with the created Start Menu folder even if the folder is renamed and/or moved-copied elsewhere inside Start Menu!


A little bit enhanced in order to manage shortcuts that have been copied/renamed from current user to all users and vice versa :-)