Sebastian
Sebastian

Reputation: 4811

Write a file to Roaming folder using NSIS script

I am using NSIS to make exe for a desktop application in c# and i have to write few files to the AppData Roaming folder for the user

I tried the below code

 !define ROAMING_FOLDER_ROOT "$APPDATA\APPDUMMY\APPFILES"
 MessageBox MB_OK 'AppDATA FOLDER "${ROAMING_FOLDER_ROOT}"'  #here i am getting the correct path of the Appdata roaming folder frm variable
Section -Additional
SetOutPath "$ROAMING_FOLDER_ROOT"
SetOverwrite off 
File "C:\MYAPPSOURCECODE\BIN\BookStore.sqlite"
SetOverwrite ifnewer
File "C:\MYAPPSOURCECODE\BIN\AppSettings.xml"
File "C:\MYAPPSOURCECODE\BIN\Resources\defData.xml"
File "C:\MYAPPSOURCECODE\BIN\Resources\dummy.html"
SetOutPath "$ROAMING_FOLDER_ROOT\Resources"
File "C:\MYAPPSOURCECODE\BIN\Resources\appjsfile.js"
SectionEnd

While i am trying to do the same with $LocalAppData its writing to the AppDAta Local folder but i want to make it writable to Roaming folder

Upvotes: 1

Views: 2604

Answers (2)

Anders
Anders

Reputation: 101756

If you look at the code you posted you see that in the MessageBox call you referenced the ${ROAMING_FOLDER_ROOT} define but when calling SetOutPath you are referencing a variable called $ROAMING_FOLDER_ROOT and this probably produces a compiler warning. Make sure that you use the ${} syntax when accessing defines!

NSIS has a concept called the shell context and the $AppData constant is affected by this:

SetShellVarContext current ; Current is the default
DetailPrint AppData=$AppData ; C:\Users\%username%\AppData\Roaming
SetShellVarContext all
DetailPrint AppData=$AppData ; C:\ProgramData (This is in the All Users folder on XP)
SetShellVarContext current ; Restore it back to the default

Upvotes: 3

Serge Z
Serge Z

Reputation: 425

Ah, seems, you are using common shell context Try to set

SetShellVarContext current

before you are getting $APPDATA.

 Var ROAMING_FOLDER_ROOT 
 MessageBox MB_OK 'AppDATA FOLDER "${ROAMING_FOLDER_ROOT}"'  #here i am getting the correct path of the Appdata roaming folder frm variable
Section -Additional
SetShellVarContext current
StrCpy $ROAMING_FOLDER_ROOT "$APPDATA\APPDUMMY\APPFILES"
SetOutPath "$ROAMING_FOLDER_ROOT"
SetOverwrite off 
File "C:\MYAPPSOURCECODE\Models\BookStore.sqlite"
SetOverwrite ifnewer
File "C:\MYAPPSOURCECODE\BIN\AppSettings.xml"
File "C:\MYAPPSOURCECODE\BIN\Resources\defData.xml"
File "C:\MYAPPSOURCECODE\BIN\Resources\dummy.html"
SetOutPath "$ROAMING_FOLDER_ROOT\Resources"
File "C:\MYAPPSOURCECODE\BIN\Resources\appjsfile.js"
SectionEnd

Upvotes: 2

Related Questions