Jason94
Jason94

Reputation: 13610

NSIS: Deleting a folder upon uninstall

I want to delete the Startmenu\XXX folder and Program Files\XXX menu upon uninstall for the application.

Tried RMDir /r but this does not work for me. (Windows 7)

Upvotes: 3

Views: 17862

Answers (3)

Andy
Andy

Reputation: 902

Occasionally Windows won't let you remove a folder when it's still in use. The solution is to mark the folder (and/or files) for deletion on next system reboot. For this, use the flag /REBOOTOK

For files:

Delete /REBOOTOK "<filename>"

For folders

RMDir /R /REBOOTOK directoryname

After next reboot, the files/folders will be removed.

See also: http://nsis.sourceforge.net/Reference/RMDir

Upvotes: 5

Joe DF
Joe DF

Reputation: 5548

Here's your solution: add "SetShellVarContext all"

http://nsis.sourceforge.net/Shortcuts_removal_fails_on_Windows_Vista

Example code:

OutFile Win7.exe
Name Win7

Section
  SetShellVarContext all
  CreateDirectory "$SMPROGRAMS\Win7 Testing"
  CreateShortcut  "$SMPROGRAMS\Win7 Testing\win7test.lnk" "$WINDIR\notepad.exe"
  WriteUninstaller "$EXEDIR\uninst.exe"
SectionEnd

Section uninstall
  SetShellVarContext all
  Delete "$SMPROGRAMS\Win7 Testing\win7test.lnk"
  RMDir "$SMPROGRAMS\Win7 Testing"
SectionEnd

-joedf

Upvotes: 3

Anders
Anders

Reputation: 101606

RMDir is the correct instruction, your path is probably wrong.

A common issue with startmenu removal is forgetting to use RequestExecutionLevel, see this page on the NSIS wiki

Process Monitor can help you detect path and privilege issues...

Upvotes: 6

Related Questions