The Windows Registry is used to store information and configuration settings for software, hardware devices, user preferences, operating system configurations, and much more. For example, when a new program is installed, a new set of instructions and file references may be added to the registry in a specific location for the program, and others that may interact with it, to reference from it information like where the files are located, which options to use in the program, and so on.
Below I have put together certain ideas I find to be good practice in which you should try to implement when using
custom.nsh. These are just some code snippets for general use which should make your life easier. First, I'd like to outline some things you should be aware of when using the registry while making a portable application with NSIS.
HKLMis for values that affect all users on the host computer.
HKCUis for values that affect only the current user on the host computer.
- You do not need to be elevated to write under
HKCUbut you do need administrative rights when writing to
HKLM; this doesn't include reading from
- Be aware of Registry Redirection as this is a common mistake when trying to read/write to/from the registry.
It's usually a good idea to check for errors when reading from the registry. For example:
WriteRegDWORD, it is better to use something like
0x00000409 than it is to use
409. However, when using
[RegistryValueWrite] in the
Launcher.ini file it is better to use the decimal number system and not the hexadecimal number system. In the example below we're using two different methods to write the same value to the same key using this idea:
There is no 64-bit NSIS installer which means your launcher will always be a 32-bit process when running on 64-bit PC. This means that 32-bit redirection will take place. On Windows x64 the registry redirectorYou can find more details on this topic by reading this article. ensures that 32-bit applications which try to access their sections of the registry (e.g.
HKLM\Software\Classes) actually get redirected to the corresponding entries in the
Wow6432Node sub-tree. Similarly, the file-system redirector ensures that 32-bit applications which try to access the Program Files folder are redirected to Program Files (x86) instead. This is discussed in the next topic in greater detail.
So if a 32-bit installer tries to install a 64-bit application, the files and registry keys will end up in the wrong places. However, a 32-bit application can read and write to a 64-bit registry node by using
More to come soon.