Search code examples
installationnsisappdata

How to delete a directory in windows %appdata%(or %programdata%) using NSIS


I am building a setup using NSIS. In my setup, i need to delete a folder (and its contents) in the windows %appdata% (or %programdata% in win7) on uninstallation of my application.

As i am relatively new to NSIS, Kindly Requesting you for a Function or a piece of script that i can use in my setup to execute this operation.


Solution

  • For local user only:

    RMDir /r "$APPDATA\YourApp"
    RMDir /r "$LOCALAPPDATA\YourApp"
    

    For all users:

    SetShellVarContext all
    RMDir /r "$APPDATA\YourApp"
    RMDir /r "$LOCALAPPDATA\YourApp"
    SetShellVarContext current
    
    • Option /r - required to delete subfolders.
    • Option /REBOOTOK - required for delayed removal (after system restart).

    To delete files only use:

    Delete   "$APPDATA\YourApp\*.*"