Applications that only use files in their folder are naturally portable, but most of them use registry, files and folders on host computer (local).
Prepare portable
Get program files
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).
-------------------------------------------------------------------------------------------------------
Monitor running and/or setup
Launch
Total Uninstall, click Install, Browse to CCleanerPortable\App\CCleaner\CCleaner.exe
Click on Next to Build A New Snapshot
Click on Next to Launch setup application Now
CCleaner launch in english. Look in Options-Advanced that Save all settings to INI file can't be uncheck (due to portable.dat file). Choose your language in Options-Settings and close CCleaner.
Click Next in Total Uninstall to Make the post install snapshot and find the changes. Click Close to view 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
Copy-paste the script below in Notepad++ and save as CCleanerPortable.nsi in CCleanerPortable folder.
Right-click and Compile NSIS Script, it will create a some tens of kB executable :
-----------------------------------------------------------
WindowIcon Off
SilentInstall Silent
AutoCloseWindow True
OutFile CCleanerPortable.exe
Section
ExecWait "$EXEDIR\App\CCleaner\CCleaner.exe"
SectionEnd
----------------------------------------------------------
- launcher don't display icon
- launcher don't display screen output
- launcher automatically close when completed
- launcher name will be CCleanerPortable.exe
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
Open in Notepad++ CCleanerPortable_2.nsi.
Added: version info, securities before starting, customization, splash and passing receipts parameters.
You will need
FindProcDLL plug-in: download and install Optimized by size binaries.
-----------------------------------------------------------------------------------------------------
Final launcher
Open in Notepad++ CCleanerPortable_3.nsi.
Same script than 2, but common parts with all launchers are moved to PortableApp.nsh called with !include.
-----------------------------------------------------------------------------------------------------
Backup and restore registry keys
Registry plug-in
You will need this
NSIS plug-in for registry to compile.
Download, extract and Install (in Desktop): it will copy Registry.dll in Plugins and Registry.nsh in Include.