Skip to content
⌘ NSIS Forum Archive

How to remove multiple $APPDATA

3 posts

scottbay#

How to remove multiple $APPDATA

My application saves data into application data folder for each user.

"C:\Documents and Settings\USER_A\Application Data\Company\AppName"
"C:\Documents and Settings\USER_B\Application Data\Company\AppName"
"C:\Documents and Settings\USER_C\Application Data\Company\AppName"

My own MFC based uninstaller removed these folders using CFileFind, FindNextFile, IsDirectory, GetFilePath...

Now I'm rewriting my setup program using NSIS.
I think that this $APPDATA removal feature is frequently used one in uninstallation. However I couldn't find out APIs or relevant sample. Is there any easy way to do this? or function sample?

Thanks in advance
evilO#
Hi 🙂 !

As far as I know there is nothing available, but you could use this code, assuming that the users names are stored in a string named "users", separated by "|". For instance: "user_A|user_B|user_C"

!include StrFunc.nsh
!include LogicLib.nsh
${StrTok}
${UnStrFunc}
${UnStrTok}
/*
your defines / code / etc
*/
Function un.RemoveAppData
  Push $0 ; Token Counter
  Push $1 ; Current token (user)
  
  ; Initialises the counter
  IntFmt $0 "%d" 1              
  
  ; Get the first user
  ${UnStrTok} $1 $users | $0 1    
  
  ; Loop until there are no more users
  ${DoUntil} "$1" == ""         
    MessageBox MB_OK 'Removes "C:\\Documents and Settings\\$1\\Application Data\\Company\\AppName"'
    
    ; Removes the AppData directory for the current user
    RMDir "C:\\Documents and Settings\\$1\\Application Data\\Company\\AppName"
    
    ; Increment the token counter
    IntOp $0 $0 + 1
    
    ; Get the next token
    ${UnStrTok} $1 $users | $0 1
  ${Loop}
  
  Pop  $1
  Pop  $0
FunctionEnd 



evilO/Olive