Portable Application Template 2.6 released

Submitted by Klonk on December 10, 2007 - 3:13pm.

What ist it for?
It helps you to create a clean portable application. This means no traces are left on the host computer and the application doesn't (normally) have to be changed in any way. (Maybe some configuration files)

Where can I get it?
http://www.loncarek.de/downloads/ApplicationPortableTemplate.nsi
use "Save As..." in your browser.
The license and more information could be found at the end of the source.

What to do to make an application portable?
1. You install the application you want to make portable on your computer.
2. You monitor which files, folders, and registry keys are generated. (There are several helper apps for that task).
3. You insert the monitored information into the constants at the beginning.
4. Then create a correct directory structure and compile the script with NSIS. Create an launcher icon.
5. Copy your application to the appropriate APP folder and also the launcher.
6. Run the launcher.
That's it...
It might happen that some applications need some additional handling, but that should be left to intermediate/advanced users as some routines would have to be added.

How does it work?
Existing Application files and folders are renamed. Registry keys saved. Then the files/folders/registry keys of the portable application are applied. Finally the Application is launched.
When the application is closed all files/folders/registry keys are saved within the data directory of the portable application and all original files/folders/registry keys are restored.
The users profile folder could redirected to the portable data directory.

Which application can I make portable?
Almost every application as far it does not implement itself too deep in the system. Also some commercial applications could get portable. But then respect the license or offer only the source to others.

What is this standalone launcher/installer thing mentioned in the history?
When I started creating this template I had in mind to create launchers especially for commercial applications. As you sure know most commercial applications do not allow to sher them with others. Now you can simply distribute your compiled launcher. It then will create the default directory structure, optionally files for PAF compatbility, copy the locally installed application into the portable apps folder and optionally compress it with UPX. Also some default files are extracted. So an end user wanting to create a portable version of his favorite commercial application doesn't have to do anything special. Simply start the launcher.

What license?
The license is a 2-clause BSD-style license. (see source for details)

What is needed?
In order to compile this script with NSIS you need the following Plugins:
- NewAdvSplash
- Registry
- FindProc
- Dialogs
Those Plugins can be found here: http://nsis.sourceforge.net/Category:Plugins
Last tested with NSIS 2.30

Where can I find more informations about all the possible settings/constants?
This is easy. Simply open the script with your favorite editor/reader an go to the end of the source. There is plenty of explanation and documentation. If I forgot something please tell me, so I can add it.

History (since version 2.3):
Discussion/History until version 2.3:
http://portableapps.com/node/6709
2.4
- added extraction/creation of several stuff to get PAF compatible portable applications
- added some error handling and messageing
- fiexd: is now also capable of reading registry files (unicode) created from regedit version 5 and up (used since WinXP Before they were deleted.
- added more options for creating a standalone launcher/installer
2.5
- changed cleanup of newadvsplash to reflect changes to newest version
- fixed some wording in docs
- fixed commandline parameters being given as one string
2.6
- added: check for required write access to registry,if not possible the launcher exits
- updated PAF compatibility (creation of appinfo.ini)
- added additional variable for long application name (for descriptions)
- Registry keys are now stored in file ".reg", e.g. TestApp.reg

Any comments/bug reports are welcome.

( categories: )

Great template!

Your template works perfect! Very cool! Thanks alot!

quicky

Some postings that might be of interest to PAT 2.4 users

Since Portable Application Template 2.4 is now out in the wild, and I don't expect people to read through the 2.3 thread, I'm allowing myself to publish a few direct links to posts, that I posted there after the release of 2.4 (which I at that time hadn't yet been made aware of), which I assume are still valid and therefore of might be of interest to PAT users (including myself, and hopefully the developers of PAT).

http://portableapps.com/node/6709?page=1#comment-59128
NSIS 2.33, plugins and newadvsplash::wait

http://portableapps.com/node/6709?page=1#comment-59145
Specifying ICON?

http://portableapps.com/node/6709?page=1#comment-59146
parent v.s. child registry keys

http://portableapps.com/node/6709?page=1#comment-59228
EXEPARMS are passed to application as ONE string - NOT tokens

http://portableapps.com/node/6709?page=1#comment-59238
Java support and Portable Application Template 2.3 [/2.4]

Hope You don't mind, me "reposting" these here.

Thanks for pointing to it

I wasn't aware of this stuff (hadn't the time to monitor this forum all the time).

Regarding ICON:
I haven't found any way to do so. Maybe there is a plugin. At least haven't found one yet.

Regarding Java Support (Copied from docs within):
...
Which directory will be scanned for the JAVA/GTK version that will be used
(highest priority first):
A. "App\JAVA" or "App\GTK"
B. "CommonFiles\JAVA\" or "CommonFiles\GTK\"
C. "CommonFiles\JAVA" or "CommonFiles\GTK"
D. on the host computer installed JAVA or GTK

Remarks: When the above A and B do not exist C will be used regardless of the
installed version. It is highly recommended to use B as far as possible if you
want to share it with other portable applications. If your application does not
require a special GTK/JAVA version it is recommended to use C with the newest
available version of GTK/JAVA. should be only the version number
e.g. "1.6.0_01", otherwise it won't be found. A message will appear when the
hosts JAVA/GTK will be used.
...

So already there is support for multiple version in some respect.
You could have a java version together with your application in folder "App\JAVA". If it's not there you could have a different version in "CommonFiles\JAVA\" if the required is not found the version within "CommonFiles\JAVA" will be used. If still there is no Java the host computers java will be used.

So I hope this is clear now.

But it is not intended to make Java itself portable. It is only used to give a portable application access to java it might need.

Java support and Portable Application Template 2.5

Hi Klonk,

I'm fully aware that one cannot monitor everything all the time. I can't, and I don't expect You to be able to do that either. No problem!

Thanks for Your explanation about how Java is supposed to be supported in PAT. Your description matched exactly what I had managed to understand by "reverse engineer" PAT, and from the documentation that found in PAT itself.

The current implementation implements the concept You describe.

Unfortunately, IMHO, the conception of how Java works is not correct (no offense). I beg You to re-read what I wrote in my post with subject Java support and Portable Application Template 2.3 [/2.4].

In a nutshell, what's needed is to be able to just specify 'java[.exe]' or 'javaw[.exe]' in the !define EXE statement.

If one has specified an executable w/o an absolute/relative path, your template needs to look for 'java[.exe]' or 'javaw[.exe]' in the "allowed" places and, if found, "canonicalize" the path to the java[w] executable and substitute the specified executable (w/o an explicit path) with the canonicalized path.

Let me know if You need more information to get this right.

Location of the Registry.reg file?

Karl,
I was unable to get the Registry.reg manipulating code to work with the .reg file stored as "portableappdir\Data\Registry\Registry.reg". The file was not found at all. I put in some MessageBox printouts and learned that the code wanted the Registry.reg file stored in the Data directory itself, as "portableappdir\Data\Registry.reg". I may have misunderstood your directory setup instructions at the bottom of the file but I think they say that the Registry.reg file is supposed to be put into the "portableappdir\Data\Registry" directory. If the code is supposed to work with the Registry.reg file in this directory then I think your code needs to have this modification:
(using as an example one of the lines that manipulate the Registry.reg file:)
IfFileExists "$DATADIR\Registry.reg" 0 InitRegUseVar
changes to:
IfFileExists "$DATADIR\Registry\Registry.reg" 0 InitRegUseVar
Did I misunderstand where the Registry.reg file is supposed to be placed?
-- Don

Ahem

thanks for pointing to that. Formerly for each key an own file was created. But now only one Registry.reg file is created. Thus the subdirectory "registry" is not needed anymore.

Therefore the documentation at the end is wrong. I'll update it and upload it again, but I will not use a new version number as only some text was changed.

Error in PAT 2.5 concerning the handling of USEGTK (and USEJAVA)

Hi Klonk,

while using Your PA Template 2.5 with an application making use of GTK I noticed that You're adding the path of the "portable" GTK to the end of the PATH environment variable. This is fine as long as the user doesn't have a path to a GTK installation in his PATH. If (s)he already has one, that version would be used instead of the "portabe" GTK. To remedy this situation one should prepend the path, to the "portable" GTK installation, to PATH instead of appending it (as it's done in 2.5 - and in earlier versions too, I assume). This will make the PAT-based portable application pick up the right installation of GTK.

To accomplish this one has to change line 594 from reading:

System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", "$R0;$GTKDIR\bin").r0' ; set new path

to read:

System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", "$GTKDIR\bin;$R0").r0' ; set new path

This will give the "portable" GTK installation higher precedence.

The same is true for USEJAVA, 5 lines higher up in the template.

Thanks

you are right, I fixed this and uploaded 2.5.1

How does NSIS work?

How does NSIS work?

π(pi)=3.14159265358979323...
The other night, I had a nightmare. I dreamt, that.... My dad, no I can't say it, HE INSTALLED VISTA ONTO MY PC!!!!!!!!!!!
Somebody give me a portable video editor... Please!

See here:

http://nsis.sourceforge.net
hier you should find more information about nsis.

NSIS is intended to create installers. IN fact the launcher you could create with this template is kind of "abuse" of NSIS, but works.

I mean how do you compile

I mean how do you compile it?

π(pi)=3.14159265358979323...
The other night, I had a nightmare. I dreamt, that.... My dad, no I can't say it, HE INSTALLED VISTA ONTO MY PC!!!!!!!!!!!
Somebody give me a portable video editor... Please!

Use

Smithtechs NSIS Portable.
You might have to add some plugins though.

"I was just out walking my rat and I seem to have lost my way" - James Bond in Diamonds are forever

Oh, I found an NSIS Portable

Oh, I found an NSIS Portable on Sourceforge

π(pi)=3.14159265358979323...
The other night, I had a nightmare. I dreamt, that.... My dad, no I can't say it, HE INSTALLED VISTA ONTO MY PC!!!!!!!!!!!
Somebody give me a portable video editor... Please!

And I meant how do you

And I meant how do you compile it as in every time I click compile it says there is a bug

π(pi)=3.14159265358979323...
The other night, I had a nightmare. I dreamt, that.... My dad, no I can't say it, HE INSTALLED VISTA ONTO MY PC!!!!!!!!!!!
Somebody give me a portable video editor... Please!

could you post the bug?

maybe youre just missing a plugin...but I know, NSIS errors can be difficult to decipher Smiling

"I was just out walking my rat and I seem to have lost my way" - James Bond in Diamonds are forever

The NSIS portable I got from

The NSIS portable I got from sourceforge says it comes with all the plugins.

π(pi)=3.14159265358979323...
The other night, I had a nightmare. I dreamt, that.... My dad, no I can't say it, HE INSTALLED VISTA ONTO MY PC!!!!!!!!!!!
Somebody give me a portable video editor... Please!

well...

maybe a plugin got updated and the template too but you still have the old one?
The one I found at Sourceforge is from nov. 07 and since then at least the newadvsplash-Plugin got updated. And if you want to compile the latest PortableApps-installers you have to download the MoreInfo plugin.

So check which plugin gives you the error and update that.

"I was just out walking my rat and I seem to have lost my way" - James Bond in Diamonds are forever

Sorry for that...

I have not had enough time to update it, I'll check the plugins that have new version to add them, and NSIS (I think it's in version 2.34) when I make it I'll post it here.

Path Variable Setting

Is there any chance of having a setting at the begining of the script that can add folders to the Path?

It would be handy to be able to add a sub folder, in the App directory, to the Path so that the portable app can get access to it.

Cheers Rochey

Hmm

would be possible..
Do you think of relative paths or simply subpaths of the Apps folder?

I was thinking of the apps

I was thinking of the apps folder itself and sub folders of the apps folder.

I was trying to make zenmap portable but when the zenmapPortableLauncher launches zenmap.exe in the apps directory, zenmap.exe opens but can't find nmap.exe which is in the same directory. So I am assuming that local directory is where zenmapPortableLauncher is and not the apps directory.

Hope that makes sense.

Rochey

A request

Hi Klonk,

I posted the following request today and am requesting you seperately to assist me if you can.
QUOTE:

I do not understand anything in apps development and will be very grateful if someone can help me in making a portable version of "LockLizard Safeguard Viewer 2.5.65".

The software version of the software is available at the website: http://www.locklizard.com.

UNQUOTE

Rgds,
Sahak

registry.reg

After some days of reading code and forum posts I have a question and a request.

Scenario: I am trying to use this fantastic template to portablize WinPT. The registry keys are put into registry.reg as such


REGEDIT4

[HKEY_CURRENT_USER\Software\WinPT]
"Extensions"="1"
"nKeys"="0"

[HKEY_CURRENT_USER\Software\WinPT\Keyserver]
"Default"="http://wwwkeys.nl.pgp.net"

[HKEY_CURRENT_USER\Software\GNU]

[HKEY_CURRENT_USER\Software\GNU\GnuPG]
"HomeDir"="E:\\PortableApps\\CommonFiles\\gpg\\Data"
"gpgProgram"="E:\\PortableApps\\CommonFiles\\gpg\\App\\gpg.exe"
"OptFile"="E:\\PortableApps\\CommonFiles\\gpg\\Data\\gpg.conf"

program loads and runs fine, however on exit the registry.reg gets overwritten with.


REGEDIT4

[HKEY_CURRENT_USER\Software\GNU]

[HKEY_CURRENT_USER\Software\GNU\GnuPG]
"HomeDir"="E:\\PortableApps\\CommonFiles\\gpg\\Data"
"gpgProgram"="E:\\PortableApps\\CommonFiles\\gpg\\App\\gpg.exe"
"OptFile"="E:\\PortableApps\\CommonFiles\\gpg\\Data\\gpg.conf"

The GnuPG keys are properly removed from the registry, but the WinPT key is left behind.

Question: Any notion as to what I am doing wrong?

Request: Would it be possible to use variables in the registry.reg so that it may look something more like


[HKEY_CURRENT_USER\Software\GNU\GnuPG]
"HomeDir"="{PORTDRIVE}:\\PortableApps\\CommonFiles\\gpg\\Data"
"gpgProgram"="{PORTDRIVE}:\\PortableApps\\CommonFiles\\gpg\\App\\gpg.exe"
"OptFile"="{PORTDRIVE}:\\PortableApps\\CommonFiles\\gpg\\Data\\gpg.conf"

I would think using WordReplace in the RegFileToStack could take care of the replacing it on the way into the registry, but I have no idea how to have it do the reverse when exiting.

Thank you very very very much.

Key ID: 0xDAE3095F
Fingerprint: 5D98 65D2 1844 21A5 76C1 F0F6 4BE6 D689 DAE3 095F

is there

that can shed some light on using this as I get errors when I try it and as I'm just starting to learn, have no idea what some of them mean?

And also, does this create the installer for you? Or is that done by something else?

Portable Template

What about making this a portable tool? After all most of us, even those using NSIS, may not keep or keep up to date most of the stuff required by this template.

What I'm suggesting is to create a compressed file with NSIS, UPX, plugins... and the template. People would simply need some editor (VIM, EclipseNSIS) additionally.

That's just a suggestion.

Delete registry keys

The registry keys can be save and restored which is very nice but just not that clean. After settings some REGKEYS "HKCR\Foo||HKCU\Software\Classes\Foo" those two keys remained after closing the application. Is there a way in the template to delete them after closing the application, just like the files.

Most applications here don't use the template. Strangely? Anyway my point is: There are not many examples.

The template is unofficial,

The template is unofficial, and major overkill in most cases because it tries to give a small example of each possibility (settings in APPDATA, registry handling, etc.) Your best bet would be to look at the 7-Zip, Sumatra, Notepad++ and Firefox launchers for examples. 7-zip for registry, Firefox for APPDATA, Sumatra for simple moving of files, and Notepad++ for updating the current drive letter in a settings file.

The developer formerly known as ZGitRDun8705

Strange

here it works fine.
BTW: Deleting at the end of application is done in Funtion "Cleanreg" quite at the bottom look for "${registry::DeleteKey}"

And yes this template is not official, I created it to have something "universal" that should work for most applications. I had especially in mind that it could be used to make commercial applications portable.
Another goal was to give maximum flexibility but it should still be usable by persons new to NSIS.

Of course there might be always applications that require some very special settings.

I optimized the code so only the really needed stuff is compiled by NSIS and the rest is ignored.

BTW: There is extensive documentation at the end of the file.

Still it has many good

Still it has many good features and doesn't slow down much. The coding style is also way cleaner than the spaghetti code of the official releases.

I'm currently changing to remove the extra stuff that I believe is not needed: Copy app files, creation of INI, copy source files, etc. and I split the file in two. The launcher and the settings which are application specific (with some callbacks for advanced stuff possible). I also fix some issues:
- Terminate only after the last process quit.
- Clean registry and faster by renaming registry keys.
- Other stuff.
This way the launcher can be updated (to fix something for example) while keeping the script settings untouched.

I may post it here if people are interested.

question

Where in the script does it delete user defined registry keys. i got most of my program i am scripting portable but the registry wont delete for me, and ive tried a lot of things to get it to work. Any help on this would be appreciated

An eye for an eye makes the whole world blind.
Mahatma Gandhi,
Indian political and spiritual leader (1869 - 1948)

Look

at function "cleanreg" quite at the bottom

I'm interested

Well in fact, when the code is changed you normally only have to copy the few lines with your config at the beginning of the file.

How do you do terminating after last process quits?
Do you rename registry keys and later rename them back for faster operation?
My intention was that existing registry keys could be used for very first usage.

PAT vs PAC

Cool! But, which is better, portable app creator, or this. Actually, maybe you two should team up. Also, to make it more portable, is it ok to use both applications on a program I want to make portable?

Edit: Now that I look at it, PAC looks a bit more user friendly.

PAT is simply a template

PAT is simply a template script, PAC attempts to create a portable app, but by the author's own admission, it doesn't really make the app portable, the paths are hard coded, so if you move the app, it will fail. Also, PAC creates the launcher using AutoIt, where PAT is an NSIS script, and NSIS is the "official" language used for PortableApps.com launchers.

The developer formerly known as ZGitRDun8705

huh?

I dont get what the difference is. Can you explain it a bit more.

PAT is a template. It is

PAT is a template. It is only code, you must replace some values in it to set it up for a specific app.

PAC is an application. It monitors the app that you are attempting to make portable, collects the reg keys and settings dirs that it creates, then automatically puts them into the script for you. It also uses a different scripting language, and the author said it doesn't actually make the app portable anyway.

The developer formerly known as ZGitRDun8705

Well...

Acrording to a post in OAC, this doesn't allow full portability either.

That would be up to the

That would be up to the user, they must accurately enter the info for which directories and reg keys to clean up. If the user can do that, it will allow full portability. This template does need an update though in order to comply with the latest PAF specifications.

The developer formerly known as ZGitRDun8705

will it work w/o access to registry?

ok, on this specific computer i can't access the ragistry at all. regedit dosn't work. saving a .reg fiole and merging it dosn't work. i thingk its a group policy thing, so theirs no way around it. will the program still work?

Depends

very much on your application. The template itself will.
But if you r application requires access to the registry then I'm pretty sure you will have problems.
I'll add checking for this into 2.6.

a tiny nit

This template is great. Very helpful. The code is also very readable (as another user commented). Kudos.

I have one tiny nit: the template should have a 'long name' and a 'short name' macros. For example, some apps may have spaces in their official, 'long' name (e.g., "Mozilla Firefox, Portable Edition"), while the exe and folders should probably not have spaces and use a 'short' name (e.g,, "FirefoxPortable").

In the current template (2.5), I got around this by changing the DESCRIPTION macro (line 88) to be the 'long' version and then changing lines 226 and 230 from this

VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${APP} Portable"
VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "Allow ${APP} to be run from a removeable drive. This launcher is based on the Portable Application Template created by Klonk (Karl Loncarek)."
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Launcher created by ${AUTHOR}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "by ${AUTHOR}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "${APP} Portable"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${VER}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "OriginalFilename" "${PNAME}.exe"

to this

VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${DESCRIPTION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "Allow ${APP} to be run from a removeable drive. This launcher is based on the Portable Application Template created by Klonk (Karl Loncarek)."
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Launcher created by ${AUTHOR}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "by ${AUTHOR}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "${DESCRIPTION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${VER}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "OriginalFilename" "${PNAME}.exe"

e.g., they use "${DESCRIPTION}" rather than "${APP} Portable".

In fact it

has to be changed in some more places. I'll add this, but name it LONGAPP. Additionally I'll correct generation of appinfo.ini to be compliant to the lates PAF format draft. Version 2.6 is coming..

I have 2 comments/changes

I have 2 comments/changes that I think would help with PAF compatibility.

1. The registry entries should be saved as ${APP}.reg

2. All the settings should go under ${App}Portable\Data\settings\

I think this is the way all the apps on this site are headed if they aren't already formatted this way. Hopefully you can update this for the next version.

OK

I change this. Look out for version 2.6.1...

edit:
after looking into it I do not see the need for creating a settings directory. The only thing that is created is the registr.reg file or now ${APP}.reg file. So I haven't changed that yet.

I'm against creating another directory for only one file! This simply does not make sense. Sure if it were more files, then I'll agree...

The backup function of PAM

The backup function of PAM uses this file structure and most apps are moving towards this, that's the reason I suggested it.

settings

Settings is not in the spec, it is just a convention. John commented on this in his spec post. As long as the reg is beneath Data it will get backed up as PAM backup works on the entire Data directory, not just settings.

formerly rayven01