Skip to content
⌘ NSIS Forum Archive

Compile time "My Documents"

5 posts

mmullikin#

Compile time "My Documents"

I'm trying to make a script portable from machine to machine (ie. work desktop to work notebook to home desktop). The files that need to be added into the installer are located in a sub-folder off of "My Documents" folder. Problem is that my user name varies from machine to machine.

Is there a way of getting and using the compile-time "My Documents" folder as a variable?

TIA! 😁
Afrow UK#
Yes it is. Firstly, compile this script and place the output .exe (GetMyDocs.exe) in the folder that your main .nsi script is.

OutFile "GetMyDocs.exe"

Function .onInit
FileOpen $R0 "$EXEDIR\MyDocsPath.txt" w
FileWrite $R0 '!define MyDocuments "$DOCUMENTS"'
FileClose $R0
Abort
FunctionEnd

Section
SectionEnd
Then you just need to put this at the top of your main .nsi script:

!system "GetMyDocs.exe"
!include "MyDocsPath.txt"
Then the constant ${MyDocuments} will be your current local My Documents path.

Edit: Never mind, that works 🙂

-Stu
Takhir#
2 notes:
1. My Documents folder location might be changed (Windows has copy hook to system folders, so in most cases it tracks these folders location).
2. In russian (and not only 😉 ) this folder may have another name.
Finally you can find path in the registry, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, Personal
mmullikin#
Thank you very much! 👍

I went with kichik's solution since the script needs only to be portable for my machines. Works like a charm!!

Once again... NSIS rocks! If it had built-in disk spanning it might just be perfect. 😉