How To Make Portable With NSIS
How To Make Portable With NSIS
Prepare portable
First of all you have to extract files from setup with a program such as Universal Extractor and if
you can't you have to install. In this case monitor setup with Total Uninstall (doing so you will be
able to clean your computer and know what need program).
The simpliest example is CCleaner, download portable and unzip in CCleanerPortable\App\CCleaner
(you can create these 3 folders at one time with Total Commander).
changes:
There is no change! CCleaner is naturally portable.
Prepare launcher
In this case launcher is useless but it can do some settings and move them in Data.
If there is no portable.dat file in its folder, CCleaner use ini file only if found in its folder. Otherwise,
use registry HKEY_CURRENT_USER\Software\Piriform.
A good thing is to force use ini creating portable.dat, another is to move ini file in Data to keep
settings when update.
Launcher can also write in CCleaner.ini to fix some settings:
[Options]
Language=1036
BackupDir=L:\PortableApps\CCleanerPortable\Backups
1036 is the decimal id of french and can be returned by GetUserDefaultLangID of kernel32, we will use
it to fix automatically language.
Launch app
Launcher is a small exe in *Portable folder compiled with NSIS. Download and install NSIS.
Minimal launcher
WindowIcon Off
SilentInstall Silent
AutoCloseWindow True
OutFile CCleanerPortable.exe
Section
ExecWait "$EXEDIR\App\CCleaner\CCleaner.exe"
SectionEnd
Code executed must be in Section: Execute CCleaner.exe and wait to quit ($EXEDIR is the path of the
launcher)
Structured launcher
Download and extract CCleanerPortableSources in your CCleanerPortable folder.
Open in Notepad++ CCleanerPortable_1.nsi.
To use always the same parts of scrpit we use constants and we use functions called in main section
to have a clear structure of running.
Lines begining with semicolons are commented and not compiled.
Read comments and search in NSIS help to understand.
Complete launcher
Final launcher
Registry plug-in
REGEDIT4
[HKEY_CURRENT_USER\Software\Audacity\Audacity]
"WantAssociateFiles"=dword:00000000
[HKEY_CURRENT_USER\Software\Audacity\Audacity\Directories]
"TempDir"="C:\\DOCUME~1\\Admin\\LOCALS~1\\Temp\\AudacityPortableTemp\\"
[HKEY_CURRENT_USER\Software\Audacity\Audacity\MP3]
"MP3LibPath"="L:\\PortableApps\\AudacityPortable\\App\\LAME\\lame_enc.dll"
Only the above registry entries have to be done by launcher (others are user settings that have to be
kept in Data).
Download Reg2Nsis and install context menu. Right-click on reg file and Convert to nsis script you
will get this .nsh file:
BackupLocalKeys
RestorePortableKeys
Settings saved in Data\Audacity.reg (when closing a previous run of portable) are merged to registry.
Init
This function force settings needed to be portable, update paths and overwrite those previously
restored.
Close
BackupPortableKeys
RestoreLocalKeys
Opposite of backup.
ICP only use Young Smart Software folder in C:\Documents and Settings\Admin\Application Data
($APPDATA for NSIS)
Download and extract InstantColorPickerPortable.
Open InstantColorPickerPortable_Lite.nsi in Notepad++
BackupLocalDirs
In Application Data, Young Smart Software folder is renamed in Young Smart Software--
BackupByInstantColorPickerPortable
RestorePortableDirs
BackupPortableDirs
ICP is closed, we do reverse of RestorePortableDirs.
RestoreLocalDirs
Reverse of BackupLocalDirs
Same way than for folders. Download this template where you will foud actions on registry, folders
and files.
If you have several of them you have to copy lines and increase index of lines with tab:
Deletion of backup not needed in normal use, but if there was a crash not recovered, old backup
prevent MoveKey.
Comment or delete constants, functions and calls not used.
Complements
Read NSIS User Manual Chapter 4: Scripting Reference to learn more about Functions, Instructions,
Variables, Constants...
NSIS Constants
Many constants ($APPDATA, $SYSDIR...) are defined in NSIS and their values depends of Windows
version and localization.
Compile Constants.nsi and run Constants.exe to write in Constants.ini the values of these constants
on your computer. They are often the same with SetShellVarContext current or all.