Compile a program for install for distribution

How do you compile a set of files , so that if you run an install it can locate files in different directories to run.

I’m thinking of trying to setup some sort of prototyping for some scripts.

I would like to send a copy to clients to test run, but I only want the script to run a couple of times, preset, then it will stop working. This way, if they like the program I can then offer them an unlocked version.

The method I was thinking of is for the install program to:

  • Install the main executable file in a directory of their choice
  • Install an ini file in a different directory, say c:/user/ProgramData/info/program.ini
  • In the ini file have a count say 5
  • The Executable looks for the ini file and each time it runs it changes the count in the ini file
  • When the count gets to a certain threshold then program won’t run
  • I do not want to mess with computer registry.


If client pays for program you give him another exe file that doesn’t check the ini file, or writes in a code to the ini file. I need to think how to do this

Alternative give a license ID for them that you can generate with installforge

Another method is to have program check a date – say install date and count for so many days- compare date to today and if after 30 days later -stop working.

So the install program should be able to :

  1. Add files into 2 places
  2. Allows for a variable so that it can find the user on the computer and put the file into the specific users only c:/user/ProgramData/info/ director
  3. create a directory for the install.

Windows iexpress.exe

There is a wiki help file How to Make an Installation File . I haven’t looked into this yet but it allows you to run a batch file on install so that you can move files across to somewhere else. There is possibility that you get an AntiVirus warning on the install because of detected batch file that could be malicious, so that may limit install sharing if people uncomfortable with AntiV warning for your install.


InstallForge download. This looks like it has a few more options to the iexpress.exe including allowing for a Serial Validation that then lets you use the program (or does it only let you unzip it?)

The below video is good as the activation gets an error and shows how to fix it

By default InstallForge puts all your files in C:\Program Files (x86)\Company\AppName\ folder, where you have filled out company and AppName at the beginning page of the setup of install file.

It doesn’t do anything to the Registry, just puts all the files in this directory. This can be a problem if you are writing to files as the C:\Program Files (x86) directory is protected and you need Admin permission to alter anything in the folder, so you can’t write to files here. If you are altering files you need to put them elsewhere, so you need to create a batch file to move files after the install.

Stop Press- I’m a bit confused on the point of writing to files in C:\Program Files (x86) directory as I’ve just run a test on the NSIS install and it writes to that directory! Weird. So maybe having writable files there is ok.

AntiVirus software may trigger a warning if there is a batch (.bat) file in your install script as you can do quite malicious stuff with a batch file. The Batch also includes ps1 or powershell scripts too.

NSIS: Nullsoft Scriptable Install System

NSIS has a window and a script option, so you can use the window setup and then generate the install script and edit the script later. I like the idea of being able to tweak the script.

Web page for help file info here

The editor he uses HM NIS Editor Download . The editor is a lot more user friendly than the basic install setup of NSIS so I’d recommend using it.

This looks a bit more complicated than the other two programs with its script setup and may allow for more choices in how you do set things up.

In the install process , see below, you could add your own License File & also a ReadMe file, which is handy for when people open the program, it allows for further documentation on the file.

The wizard setup is pretty straightforward and gets you part of the way quickly and with little hassle.

NSIS allows you to place files in different directories, which is what the above 2 programs don’t seem to do easily (iexpress & installForge) without writing a batch file to move the files later. I’m concerned that having a batch file in the install script might trigger an AntiVirus warning and stop the opening of the install file. If it does then it sort of defeats the whole process.

I haven’t found a method to protect the install or have a serial number attached to the program.

Process InstallForge

I decided to go with InstallForge and initially clicked all the bells and whistles and after building the file found it did not extract at all.

So I went for the most basic setup- after doing it from scratch, and it installed beautifully, after following this video:

I did not do anything with the registry at all. I’m keeping it simple.

When it does the install it has a preset to C:\Program Files (x86)\ (Company Name)\(App Name). So it installs all files and folders there.

If you want to locate files elsewhere, eg in C:\Users\(Current_User)\AppData\Roaming there is a comment on the forum here about creating a batch file to move the files across to that location.

I did the serial validation and as long as you have the correct serial number it works fine. It stops the install unless you have a correct serial number. So all its doing is allowing/blocking install process.

Also, the serial number can be used over and over on the same file, so once you have one serial number and a protected install file then you can use as many times as you like.

So, to have a program that runs so many times then stops you still need count from an ini file , locating ini file somewhere else.

Process NSIS

The setup wizard was easy to use. I ended up adjusting the install.exe file name so that I could be clear which version install it was.

When I ran the installer it:

1/ Added an item to my Start Menu (cool)

2/ As it did 1/ above I checked whether it was defined as a registered program , in which case it could be uninstalled. It was , so you can uninstall it the normal way

3/ I added a AppData path (without a sub directory) and it installed a couple of files in there, which was handy. This is what I wanted it to do, so I’m pleased with that. An interesting thing is that on installing it has a tab which says a file can be over written (or not) , so if you reinstalled the program you could make it such that the ini file which could have a count could not be overwritten, so it would keep the original count.

4/ It seems to have put the program into the start menu automatically, I’ll need to check that. Hopefully there is a place that stops that from happening.

5/ It creates a folder in the Program Files (x86) of the name of the app, not the company name. First time I went looking I couldn’t find a folder with a company name so couldn’t delete the program.

6/ The uninstall seemed to work, apart form the issue that I still had the program open, so it deleted everything apart from the .exe and the .ini fies (the ini file seemed to bee in same dir as the .exe as well as in AppData Dir too.

Other PC & program. Things seriously unraveling

A few things happening:

  1. Install into C:/Program Files (x86)/ dir so protected. They do not like you to write to a file here, and if they do then you have to be in Admin mode and you still get a pop-up to ask if you’re sure you want to do that.
  2. The ini file, located in C:/Program Files (x86)/ dir seems to do count.
  3. Issue with theC:/User /A_UserName/ dir it needs the % to work, so should be C:/User /%A_UserName%/ (note- slashes other way)
  4. It is writing stuff to registry – so that needs to be cleaned out on Uninstall.

The first item can be dealt with by locating the write file to C:/User /%A_UserName%/ Documents/FileSaveLaunch Dir where you can write to it with impunity.

Ended up with an error being thrown way down the code because of the %A_UserName% not being in % signs, a really confusing bug. Anyway all good now. Note there was a comment that %% were required when you had a #NoEnv at the top of the script, which I did have in this case.

Start/Startup menu confusion

I was a bit confused , in the setting up of the wizard process, when the above Window pops up . This is the setup for the Start menu (bottom right corner) , not the startup folder that I thought it was, so that was a bit of confusion sorted.

I’m not sure, if I comment out the Registry Info, whether I’ll be able to do that in the start menu. All I can do is test it and see what happens.

Further Tests with NSIS taking out Registry info and writing to the C:\Program Files (x86) directory

I’m a bit uncomfortable with messing with the registry, so for the moment I want to try and Comment out all the Registry write code in the script. This still allows me to have the Program displayed in the Start Menu. But if you go to Control Panel/Uninstall programs the program does not show up in the list at all. So you have the use the Uninstall script you created to uninstall the program as you have folders/program files in different places on your PC (rather than just deleting the folder in C:\Program Files (x86) only ). So that test worked fine.

It seems to be a clean uninstall. Actually, on checking there were still .ini and logo file in the C:\Program Files (x86) \AppName folder & I had to manually delete those. Actually, I think I’d got my install & delete in different folders for these specific files so that’s why it wasn’t working properly.

The second test was to test writing to the .TXT & .CSV files located in the C:\Program Files (x86) \AppName directory and that worked fine too, maybe NSIS gives permissions on those folders? I’m not sure, all I know is that it worked fine. Only problem, when you uninstall program your data is deleted (unless you specify those files and main directory not to be deleted)

End comment

On a simple, straightforward test of getting an install program that allows you to install files in different locations on another PC, NSIS is the only program of the above 3 that does this without resorting to .bat files.

Because of the setup process I need to write my code in a different manner to allow for some configuration options:

  1. Files may need to be located in different areas on the computer you are installing the program on and this needs to be considered when writing the code & compiling the .EXE, as once the file is compiled you cannot change it.
  2. Paths to files need to be at the top of the program so that you can easily change their path to where they will be installed. Maybe path to an ini file that then has all the other paths in it, so when you compile your file the only defined path is to the ini and you can change paths to other files (such as text file you are writing data to) in the ini file
  3. Security methods to allow program not to run need to be written into the code of the program, see the later article Setting up install files to share for prototyping with security

This is an interesting exercise to do. Its made me think more about the code structure of a program for distribution.

There is a follow on article on this topic Setting up install files to share for prototyping with security.