Introduction

In one of the projects, the task was to develop a Windows application for managing user sessions in a computer club.
The application consists of two components:

  • Shell, which is a GUI application for user interaction. This component is based on the ReactJS library and the Electron framework.
  • Java service, which runs in the background and performs a number of application business logic tasks. It also monitors that the shell process is always running.

One of the product requirements was to ensure easy installation of the software, which meant finding a solution to automate the process of component installation and environment setup.

The challenge was that the application had to run under a special Windows user account without administrator permissions. The user working under this account must interact with the system through the shell developed by us.
We have included the account setup, service installation and startup, as well as all the required additional files in the installer.

Inno Setup is an app for creating Windows installers

We have chosen the Inno Setup software to create the installer.

Inno Setup is one of the most powerful installer creators. In the 20 years since the release, it became popular among software developers and repackers, i.e. people who modify installation files.

Inno Setup supports working with the registry, execution of additional applications at any stage of the installation and using Pascal scripting to access the Windows API. Notably, there are many articles and guides for using Inno Setup. There is also a quite active community with many users ready to give advice, as well as many examples and articles about the challenges encountered and how they were solved.

A free stable version of Inno Setup Compiler is available for download on the official website. There is also a FAQ and documentation in English and third-party libraries that simplify the process of creating Inno Setup Scripts (.iss).

The classic Inno Setup Compiler application supports two scripting modes.

The easiest and most straightforward is the automatic script wizard.

Inno Setup Script Wizard

The script wizard allows you to create a complete installation file, add application shortcuts, license agreement, installation instructions and multiple installation languages. Further configuration or customization of the installation pages will require script editing.

Inno Setup Script is divided into several sections by areas of responsibility during the installation process.

Inno Setup script example

Most sections contain strings separated by parameters. Each parameter consists of a name and value, separated by a colon. Unless otherwise indicated, parameters are optional. A parameter takes the default value if not defined. Multiple parameters on a line are separated by semicolons and can be listed in any order.

Setting up the environment during installation

Now we have solved the challenge of packing the service and the shell into a single executable file using the installation wizard, but the task of creating a new user account, configuring access rights, as well as cleaning the system during app deletion remains open.

The [Code] section was used for creating and configuring a new Windows user account. Inno Setup supports running Delfi-like Pascal Script code in this section. Additional configuration or actions depending on the installation stage or system events can be implemented here.

Fragment of the [Code] section of the Inno Setup script

In our case, creating a user account was not enough. Further configuration required obtaining the SID (secret identification number) of the new user account immediately.

Fragment of the [Code] section of the Inno Setup script

We used the obtained SID in a special section [Registry], which is designed for working with the registry.

We write our shell to the registry for the new user account as a system shell so that it runs automatically when the user logs on. Also, using the obtained SID, we additionally disable access to the registry editor for this user account.

At the same time, we leave the administrator able to configure and maintain the user machine.

[Registry] section of the Inno Setup script

We used this section to implement the following:

  • Make our user account the default login account (lines 194-201).
  • Add our shell to system variables so that the service does not depend on the physical path of the executable file when restarting the shell process (lines 206-208).
  • Replace the explorer.exe with our shell for the new user account (lines 210-213).
  • Disable the access to the registry editor (lines 215-218).
  • Disable Windows welcome screen upon the first login to the user account (lines 220-227).

The “uninsdeletevalue” flag indicates that this key value is to be deleted along with the program during uninstallation. That way, previously added registry keys are also cleared during uninstall.

We have implemented the installation and startup of the service in the [Run] section. The code in this section is executed at the end of the installation process. Thus, we implemented the installation and startup of the system service during the installation of a graphical application.

There is also a [UninstallRun] section that mirrors the [Run] section. The [UninstallRun] section contains commands and files to be executed when the application is uninstalled. We used this section to stop and remove the service that would not be needed anymore if the shell is to be removed.\

Conclusion

After a product is developed, you need to think about how to deliver it to the customer. In the case of Windows software, the best way is to make a single executable file so that the user can run it, wait for the installation to complete and work without being distracted by additional configuration. Modern tools for creating installers provide great capabilities to perform all the necessary actions silently during the installation of the program.

Using the Inno Setup installer, we solved the following tasks:

  • Packed all service and shell files into a single .exe file.
  • Added application icons to the desktop and to the Start menu.
  • Created a new user account and configured all required permissions.
  • Set up the environment and correct uninstallation of the program.
  • Allowed the user to select the desired installation language.

Additional resources

The following resources were very helpful in learning this tool:

  • Thread about scripts on a forum. At the moment, the thread has grown into 9 parts. There you can find many interesting examples or ask for advice.
  • A guide to creating an installer using Inno Setup.