Prepare Portable App:

REGEDIT4 [-HKEY_CURRENT_USER\Software\(App Name)]

What It Does:

;Note: This script assumes that the program you're portablizing has created only one main entry in the registry at HKEY_CURRENT_USER\Software\(App Name). If it makes entries in multiple locations, simply duplicate the necessary lines of code to represent any other .reg files you exported. #NoTrayIcon ;Set the environment variable to your portable location so all files and folders the program creates are redirected to the portable location. Only change this variable if you choose to use a different folder structure from the one described in the post. EnvSet, UserProfile, %A_WorkingDir%\Settings ;Set the location of the program's main .exe file. It's assumed to be in A_ScriptDir\App Main_Executable = IconWorkshop.exe ;Set the location of the .reg file to run. It's assumed to be in A_ScriptDir\Settings. For this script, the .reg file I initially exported is named "Axialis_HKCU.reg". If you created any other .reg files to write to multiple locations in the registry, set them here. HKCU_Reg = Settings\Axialis_HKCU.reg ;Set the location of the .reg file that will be overwritten when program closes (the same file defined above) and set the registry key to be exported by Regedit.exe (I decided to create this variable to easily resuse and update the script for other portable apps that you make). Export_HKCU = %HKCU_Reg% HKEY_CURRENT_USER\Software\Axialis ;Set the location of the .reg file used to delete the registry keys that were added at launch. It's assumed to be in A_ScriptDir\Settings. Del_HKCU = Settings\Delete_Axialis_HKCU.reg ;Run the .reg file with all your saved settings - this will add the values to registry. The "/S" command line switch is used to silently add the registry entries, without the user being prompted to accept the changes. RunWait, %WinDir%\Regedit.exe /S %HKCU_Reg% ;Run the app's main .exe file. It's assumed to be in A_ScriptDir\App Run, "App\%Main_Executable%" ;Wait for the user to close the program before performing the subsequent actions. Process, WaitClose, %Main_Executable% ;Now that the program has closed, export the registry settings back to A_ScriptDir\Settings, automatically overwriting the file so that any changes the user made to the program's settings will be saved between sessions. RunWait, %WinDir%\Regedit.exe /e %Export_HKCU% ;Delete all the registry keys that were added at launch. RunWait, %WinDir%\Regedit.exe /S %Del_HKCU% ;Exit the script ExitApp

Hi all, many of you have probably heard of portableapps.com . I use many of their portablized programs such as Firefox, FileZilla, and others. Their method to create portable versions of apps consists mainly of using NSIS to compile portable launchers, as well as .ini files to pass parameters to the app. I began learning how to use NSIS scripting language to create portable apps of my own. I managed to create several fully functional portable apps, but it was a lot of blood, sweat, and tears to learn NSIS scripting language (particularly because I'm so used to ahk). Then it dawned on me: ahk has all the necessary commands to create the portable launchers instead!As it turns out, using AHK, IMHO, is a much more efficient way to portablize apps. Not many lines of code are needed, and from my experience, the results are significanly better than using NSIS with the portableapps.com structure (startup times are noticeably faster). I'm not sure if others have posted similar scripts, but I searched through the forum and was unable to find any relevant results, so I thought, what the hell. But if you know of any other similar scripts, please reply and post the links because I'm always interested in seeing another approach to performing the same tasks.Before getting to the script, it's necessary to collect and create the files to run an app portably (this is the case for any method used to create portable apps). Below are the steps I use to collect and create the necessary files.1. Create a folder anywhere on your computer to store all the portable app's files. The ahk script I've written assumes the user created the following folder structure:D:\Portable Folder (the drive of course can be different - I'm using D:\ as an example. For clarity throughout the post, I will refer to D:\ as the drive location)D:\Portable Folder\AppD:\Portable Folder\SettingsI also make an optional folder D:\Portable Folder\Source to keep the original ahk source code (the script posted below) as well as the icon used during the AHK2EXE compile process. But as mentioned, it's optional - only the folder structure above is mandatory for the sript to run properly (unless you change the code to suit your folder structure preferences). Personally, I prefer this folder structure to the one used by portableapps.com which creates several other folders (which for my needs are unnecessary) and nests them within other folders, making it more difficult to update any files because the user must drill down into several folders for access.2. Use RegShot to create an initial snapshot of your computer before installing a program.3. Install your desired app.4. Take a second snapshot with RegShot, and then compare.5. Export the registry keys that were made by the installed program (they will be easily identifiable by RegShot's compare). Use Regedit.exe to navigate to those keys and export them to a .reg file and place in D:\Portable Folder\Settings. As an alternative to Regedit.exe, I use RegWorkshop . It's an excellent piece of software but not free ($29.95). Some apps may create several registry keys in different locations so more than one .reg file will have to be exported. A lot of software however, usually creates a single key in HKEY_CURRENT_USER\Software\(App Name). When anaylizing RegShot's compare, you can ommit many of the registry entries that were made such as "MUICache" entries, as well as others. Sometimes it takes a bit of testing to see which registry entries are essential for the app to run properly, but usually it's a straightforward process.6. Go to the directory where you installed the app (usually in C:\Program Files) and copy all the contents into D:\Portable Folder\App.7. Using the RegShot compare file, look for any other folders and files that were created by the installed program and copy them to D:\Portable Folder\Settings. Many programs put their data files in C:\Documents and Settings\(User)\Application Data. Within your newly created D:\Portable Folder\Settings folder, you may need to create one or more aditional folders so that when the ahk script uses the EnvSet command, the app knows to put the files into the portable location. For the ahk script posted below, I had to create the following folder structure for the app to properly redirect its files to the portable location:D:\Portable Folder\Settings\Application DataD:\Portable Folder\Settings\Local Settings\Application DataFrom my experience, I notice that many apps do not obey the EnVSet command when "AppData" is specified as the environment variable. The problem is explained a little further in this post. It seems that in most cases, the program will obey the EnvSet command if "UserProfile" is specified as the environment variable. Thus, I've decided to use this in all my portable launcher scripts, and simply recreate a few folders in D:\Portable Folder\Settings as shown above.8. Create .reg file(s) used to delete all the registry keys added at launch. I'm on Windows XP and there is no command line switch for Regedit.exe to delete a registry key (the "/d" switch can only be used on Win98\Me). Thus, a simple .reg file must be created to perform the delete. To create the file, simply put a "-" before the registry entry to be deleted. Example:For more information on .reg files and regedit.exe command line, clear examples are given here 9. Uninstall the app (optional)Ok, now everything is in place. On to the script...1. Sets the environment variables to the portable location (D:\Portable Folder). This command is used so that all data files the app creates will be redirected to the portable location.2. Temporarily add settings to the registry by running a .reg file through Regedit.exe's command line switch. Many programs store their settings in the registry, so it's necessary to get those settings and temporarily add them (most apps on portableapps.com do the same).3. Once the registry entries have been added, launch the app.4. Wait until the app closes to export (and overwrite) the .reg file(s) so that any changes the user makes to the program's settings during the session are saved for subsequent sessions.5. Delete all the registry entries that were added when the app was first launched.Below is an example of a portable launcher for IconWorkshop. I chose to use IconWorkshop as an example because many apps have a similar installation behavior:1. Reg entries are written to HKEY_CURRENT_USER\Software (For IconWorkshop they're written to HKEY_CURRENT_USER\Software\Axialis)2. Data folder is created in the user's AppData directory (C:\Documents and Settings\(USER)\Application Data).3. Folder is created for temp files and other misc. files in C:\Documents and Settings\(USER)\Local Settings\Application Data .IconWorkshop is not freeware, but seeing as I paid for it, I don't see any restrictions on using an ahk script to launch it portably on my local computer. Here's the code:Optionally, you can compile the script using AHK2EXE so that a custom icon can be assigned. Just make sure the created .exe file is placed in the portable folder.Also note that I'm using Windows XP, but I've tested most of my portable launchers on other computers running Vista or Win7 and they work without a hitch. The only part of it that may need to be changed is setting the environment variables using EnvSet. I'm not sure if the environment variables on Vista or Win7 are the same as XP, but it's quite easy to find out and change the second line of code accordingly. Also note that there are some applications that are dependent on optional system files (like .net framwork), and if these files are not present in the host computer, the app will not run properly. However, thus far I have not encountered this problem with the apps I've made portable (and I've made quite a lot).I wrote this script to suit my needs. I mostly use portable apps on my local computer, but the script above also works on any other computer you launch the app in. However, if you often use your portable apps on other computers, I would suggest adding several lines of code to the script which will first backup the registry values on the host computer before overwriting them with your .reg file. After the app closes, you would then restore the host computer's original registry settings from the backup that was made at launch. This is quite simple to do - if anyone would like an example, just give a shout.As an aside, I've read several posts on the forum where people were wanting to contain all the registry values within the ahk script itself, and then use the Loop command together with the RegWrite command. IMHO, this is unnecessary, and actually forces the script to work harder, ultimately affecting performance. Microsoft's built-in Regedit.exe was made for this purpose, and works extremely fast at processing registry entries.I'm not a professional coder, so if anyone has any suggestions on how I could improve the script, or go about things in a different way, please share