Open “Portable Application.nsi” from directory “Templates” using your text editor. Now save it to “C:Portable My Notes KeeperSource” directory and rename it to “Portable My Notes Keeper.nsi”. Renaming is very important so do this now.
In the third line you’ll find this:
!define SNAME “Portable Application”
Select the word “Application” and open up replace dialog (in Scite: hit Ctrl+H). In the “Replace with:” field enter “My Notes Keeper”, then click on “Replace All”. Now all occurrences of the word “Application” is replaced with “My Notes Keeper” and we don’t have to change each one manually, and the possibility to make a mistake is also smaller.
There’s nothing to change until line 34 (Section “Main”). However, you can personalize your launcher if you wish, changing these lines:
VIProductVersion “0.1.0.0″
VIAddVersionKey /LANG=${LANG_ENGLISH} “ProductName” “Portable My Notes Keeper Launcher”
VIAddVersionKey /LANG=${LANG_ENGLISH} “LegalCopyright” “© tpr 2007″
VIAddVersionKey /LANG=${LANG_ENGLISH} “FileDescription” “My Notes Keeper”
VIAddVersionKey /LANG=${LANG_ENGLISH} “FileVersion” “0.1″
I think it is straightforward; change the final parts of each rows if you wish (i.e. “© tpr 2007″ to “© I am not dumbass for NSIS! 2007″). But you can also remove these five lines if you wish.
In Section “Main” you can see these lines:
;—–Importing Regkeys——
${registry::RestoreKey} “$EXEDIRportableSettings.reg” $R0
Sleep 300
${registry::RestoreKey} “$EXEDIRportableRegInfo.reg” $R0
Sleep 200
${registry::RestoreKey} “$EXEDIRportableDirSettings.reg” $R0
Sleep 200
These lines, as you may think when reading Restorekey, restores registry keys, or in other words, imports .reg files. You can see the path of the .reg file and the name of it: “$EXEDIRportableSettings.reg”
$EXEDIR: when launching the portable launcher, $EXEDIR is replaced with the full path of the launcher. So, if we launch it from “D:MyPortables”, $EXEDIR will be replaced with D:MyPortables. So the whole path looks like this:
$EXEDIRportableSettings.reg —> D:MyPortablesportableSettings.reg (if you launch it from “D:MyPortables” location).
This feature of NSIS makes it easy to handle the problem arising from the fact that the path of the portable application may change on every PC, according to what drive letter is assigned to the USB stick. It comes handy when we have to enter absolute paths to the registry also.
There are several $EXEDIR-like things in NSIS (search the forum if you don’t know what they are meaning – neither do I know each one):
$INSTDIR, $OUTDIR, $CMDLINE, $LANGUAGE, $PROGRAMFILES, $COMMONFILES, $DESKTOP, $EXEDIR, ${NSISDIR}, $WINDIR, $SYSDIR, $TEMP, $STARTMENU, $SMPROGRAMS, $SMSTARTUP, $QUICKLAUNCH, $DOCUMENTS, $SENDTO, $RECENT, $FAVORITES, $MUSIC, $PICTURES, $VIDEOS, $NETHOOD, $FONTS, $TEMPLATES, $APPDATA, $LOCALAPPDATA, $PRINTHOOD, $INTERNET_CACHE, $COOKIES, $HISTORY, $PROFILE, $ADMINTOOLS, $RESOURCES, $RESOURCES_LOCALIZED, $CDBURN_AREA, $HWNDPARENT, $PLUGINSDIR
As we have seen, MNK stores its settings in an .ini file in its program directory, so no need to import any Settings.reg into the registry. So we can delete this line. The next line contains “Sleep 300″. It tells the launcher to take a deep breath and pause for 300 milliseconds. I usually fill my NSIS scripts with sleeps to ensure that every operation has enough time to complete. 1, 2 or more extra seconds when launching won’t hurt anybody.
Because we have deleted the line with Settings.reg before, now this “Sleep 300″ also can be deleted.
The next line is “${registry::RestoreKey} “$EXEDIRportableRegInfo.reg” $R0″. It import the registration data to the Registry, so it is important. Do not delete it, and neither delete the next line (“Sleep 200″). If you plan to use MNK on a slower computer, you can increase the sleep time (but I think 200 ms is enough).
Next two lines can be deleted (“${registry::RestoreKey} “$EXEDIRportableDirSettings.reg” $R0″ and “Sleep 200″). We’ll use it when we will put absolute paths to the registry but now we don’t have to do that.
The next part is straightforward
;—–Launching My Notes Keeper——
ExecWait “$EXEDIRAppdataMy Notes Keeper.exe”
ExecWait does what its name suggests: executes the given program and waits until it (the executed program) finishes. It is handy because we want to clean up registry after the program is closed.
Note that the path uses $EXEDIR again, but after it “Appdata” comes. Now we have to see how is our main executable named. In the Appdata directory the name of the exe is “MyNotesKeeper”, so change this line to:
ExecWait “$EXEDIRAppdataMyNotesKeeper.exe”
The next part is
;—–Saving settings——
${registry::SaveKey} “HKEY_CURRENT_USERSoftwareMy Notes KeeperThe My Notes Keeper” “$EXEDIRportableSettings.reg” “/G=1″ $R0
Sleep 500
It exports the given registry key to the given registry file, then waits 500 milliseconds. Because here we don’t want to export anything, it can be deleted.
(The registry key in the code above is non-existent, it was created when doing search and replace).
Now comes the cleaning up:
;—–Cleaning up——
${registry::RestoreKey} “$EXEDIRportableRegClean.reg” $R0
DeleteRegKey /ifempty HKEY_CURRENT_USER “SoftwareMy Notes Keeper”
First, the launcher imports RegClean.reg. But there’s a problem: we don’t have any RegClean.reg yet! So let’s fix it. Open RegInfo.reg (from “C:Portable My Notes Keeperportable” directory) using your text editor and change from
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTCLSID{B0CC8D3F-EF1A-4400-A5C7-1A2230AA0B8C}]
“Days”=”584592960BAF3BEA”
“Name”=”Portable”
“Code”=”35AE664E73E18872″
to
REGEDIT4
[-HKEY_CLASSES_ROOTCLSID{B0CC8D3F-EF1A-4400-A5C7-1A2230AA0B8C}]
Notice the minus (-) sign after the first square bracket. If we import this into the registry, it will delete the whole branch (“HKEY_CLASSES_ROOTCLSID{B0CC8D3F-EF1A-4400-A5C7-1A2230AA0B8C}”).
Save it as RegClean.reg (do not overwrite RegInfo.reg!). One thing we have to do with these reg files: the first row in both files says “Windows Registry Editor Version 5.00″. Although it is fine, but change it to “REGEDIT4″ to ensure compatibility with older systems (such as Win9x).
If you want to delete only a reg value you should use the minus sign this way:
REGEDIT4
[HKEY_CLASSES_ROOTCLSID{B0CC8D3F-EF1A-4400-A5C7-1A2230AA0B8C}]
“Name”=-
This code delete registry value
“HKEY_CLASSES_ROOTCLSID{B0CC8D3F-EF1A-4400-A5C7-1A2230AA0B8C}Name” only, “Days” and “Code” will remain in the registry. But now we want to clean the whole key, so put the minus sign in front of the key name.
Now we have our RegClean.reg file, but there are some other registry keys that are present in the registry and we should remove them. Open FullReg.reg in your text editor. Although this file contains the registry changes made by the install process, we have to examine it because when launching MNK, it may write some of these settings back to the registry (especially file association keys). These are the keys we should remove:
[-HKEY_CLASSES_ROOT.mnk]
[-HKEY_CLASSES_ROOTmnkfile]
[-HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstallMy Notes Keeper_is1]
These keys may be present in your registry if you launch MNK (even if you haven’t install it). You only have to remove the main branch with the minus sign because all sub-branches are removed also. So, for example, “HKEY_CLASSES_ROOT.mnk123456123456whatstheheckisnext” is also removed when importing [-HKEY_CLASSES_ROOT.mnk].
So we have to paste these lines after existing ones in RegClean.reg. The entire RegClean.reg should look like this:
REGEDIT4
[-HKEY_CLASSES_ROOTCLSID{B0CC8D3F-EF1A-4400-A5C7-1A2230AA0B8C}]
[-HKEY_CLASSES_ROOT.mnk]
[-HKEY_CLASSES_ROOTmnkfile]
[-HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstallMy Notes Keeper_is1]
We have this line left in the script:
DeleteRegKey /ifempty HKEY_CURRENT_USER “SoftwareMy Notes Keeper”
It is not required here, so delete it. Make sure you haven’t deleted “SectionEnd” from the end of the script.
Note: there’s an NSIS script in directory “Templates” “Portable Template.nsi”. It is a general template that I’m using when I create my portables. It contains a lot of things so you should keep only those lines which you need when you build up your script for a portable. It speeds up the script-writing process and it’s more easier to replace some words than beginning with a blank .nsi file.
[...] 9. Modifying The Template [...]