I'm trying to create a setup file using Inno Setup Compiler, and I want it to install to the Documents folder as it needs to create and then delete a file, something that it can't do if it installs to Program Files. I've tried using %userprofile%\Documents
as that works in File Explorer, but that simply creates a folder called %userprofile%
wherever the Setup.exe is, and C:\Users\%username%\Documents
simply creates the %username%
folder in the Users folder. How do I get it to install into the Documents folder no matter where it is?
3
votes
Don't install to the document folder. Install to Program Files like you're supposed to. If there are non-document data files that your program needs to create and delete, store them in the Application Data folder. Your development tool should provide a method of discovering that location at run time.
– Rob Kennedy
2 Answers
5
votes
While @GTAVLover is right, you will most probably want to use the {userdocs}
or {commondocs}
constant in standard Inno Setup sections, likes [Files]
.
The syntax is like:
[Files]
Source: "readme.txt"; DestDir: "{userdocs}"
Had you wanted to refer to environment variables (what is not the right way in this case), use {%NAME}
syntax:
[Files]
Source: "readme.txt"; DestDir: "{%USERPROFILE}\Documents"
2
votes
You should use Inno Setup Shell Folder Constants to do this.
See more at Inno Setup Help.
Use ExpandConstant('{userdocs}')
where you want to get path of Documents folder (For current user).
It will return "OS Drive:\Users\CurrentUser\Documents"
.
Eg:
MsgBox(ExpandConstant('{userdocs}'), mbInformation, MB_OK);
For all users, you should replace userdocs
with commondocs
.
So, It will return "OS Drive:\Users\Public\Documents"
.