Beruflich Dokumente
Kultur Dokumente
Support
Tutorial
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 w ith 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 w ill be able to clean your computer and know w hat 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).
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 w hen update. Launcher can also w rite in CCleaner.ini to fix some settings:
1036 is the decimal id of french and can be returned by GetUserDefaultLangID of kernel32, w e w ill 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.
Copy-paste the script below in Notepad++ and save as CCleanerPortable.nsi in CCleanerPortable folder. Right-click and Compile NSIS Script, it w ill 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 w ait 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 alw ays 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 w ith 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 w ill 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 w ith !include.
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 w ill get this .nsh file:
WriteRegDWORD HKEY_CURRENT_USER "Software\Audacity\Audacity" "WantAssociate Files" 0x0 WriteRegStr HKEY_CURRENT_USER "Software\Audacity\Audacity\Directories" "Tem pDir" \ "C:\DOCUME~1\Admin\LOCALS~1\Temp\AudacityPortableTemp\" WriteRegStr HKEY_CURRENT_USER "Software\Audacity\Audacity\MP3" "MP3LibPath" \ "L:\PortableApps\AudacityPortable\App\LAME\lame_enc.dll"
C:\DOCUME~1\Admin\LOCALS~1\Temp is the system temporary directory: $TEMP L:\PortableApps\AudacityPortable is the directory containing the launcher: $EXEDIR Download an extract AudacityPortable Open AudacityPortable_1.nsi in Notepad++ In TU monitor w e saw that only one registry key was used by Audacity HKEY_CURRENT_USER\Software\Audacity but can be used by a possible installed version.
BackupLocalKeys
HKEY_CURRENT_USER\Softw are\Audacity is renamed in HKEY_CURRENT_USER\Softw are\AudacityBackupByAudacityPortable.
RestorePortableKeys
Settings saved in Data\Audacity.reg (w hen closing a previous run of portable) are merged to registry.
Init
This function force settings needed to be portable, update paths and overw rite those previously restored.
Close
Audacity is closed: delete temp folder.
BackupPortableKeys
Settings saved in Data\Audacity.reg.
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
Portable settings in Data\InstantColorPicker are copied in Application Data\Young Smart Software. (W e have to use CopyFiles instead of Rename because drives are differents).
BackupPortableDirs
ICP is closed, w e do reverse of RestorePortableDirs.
RestoreLocalDirs
Reverse of BackupLocalDirs
!define REGKEY1 "HKEY_LOCAL_MACHINE\SOFTWARE\MyProg" !define REGKEY2 "HKEY_CURRENT_USER\Software\MyProg" ;... ${registry::DeleteKey} "${REGKEY1}-BackupBy${APP}Portable" $R0 ${registry::MoveKey} "${REGKEY1}" "${REGKEY1}-BackupBy${APP}Portabl e" $R0 ${registry::DeleteKey} "${REGKEY2}-BackupBy${APP}Portable" $R0 ${registry::MoveKey} "${REGKEY2}" "${REGKEY2}-BackupBy${APP}Portabl e" $R0 ;...
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 Window s version and localization. Run NSIS_Constants to write in an ini file the values of these constants on your computer. They are often the same with SetShellVarContext current or all.