install in ProgramData folder using NSIS

Viewed 1600

I'd like to install some application data in C:\ProgramData folder using nsis installer. I'd like to avoid hardcoding it, because it may not be on C: drive.

The documentation https://nsis.sourceforge.io/Docs/Chapter4.html doesn't have any constant that defines ProgramData. What is the nsis way of installing in ProgramData folder?

2 Answers

Microsoft moved and renamed some of the special folders in Vista. %ProgramData% is CSIDL_COMMON_APPDATA and you can get that path in NSIS:

Section
SetShellVarContext all
MessageBox MB_OK "$LocalAppData"
SetOutPath "$LocalAppData\MyAppsData" 
File /r mydata\*.*
SectionEnd

You can use GetKnownFolderPath:

GetKnownFolderPath $0 {62AB5D82-FDC1-4DC3-A9DD-070D1D495D97} ; FOLDERID_ProgramData
MessageBox MB_OK $0
Related