Introduction
An application often has some configuration that is system-specific. A connection string is an example of such a configurable setting. This setting must be adjusted by the user after installation, but before using the application.
The solution presented in this article helps to guide the installing user to change the configuration settings by simply opening this file in Notepad. It is merely a service above the installation manual.
Background
In the recent past I have developed applications that needed configuration before use. For one project I made a really fancy installer class with a nice UI that asks for server and database names and that merged this info into the app.config.
The disadvantage of this approach is, that it is relatively hard to create such an installer class and even harder to maintain it. And the UI that you can create using a standard Visual Studio .NET setup and deployment project is very simple. For example, no input checking can be done.
My other option was just to instruct the installing user in an installation manual to install the program, then go to C:\Program Files\et cetera and edit the .config file that could be found there.
When developing and deploying a .NET Windows service I found that the last approach had too little service to the customer. The installing user had to adjust the CONFIG file and after that manually start the service. So I decided to search for a different solution, found none and created the one described here.
Using VBScript in the installer
My goal is really simple: open the .config file with Notepad automatically during installation. This can be done with a VBScript. To run a VBScript during installation, simply create a script, add it to your setup and deployment project and add it as a custom action, as shown in the demo code.
Notepad is opened with the .config file using this code:
Dim curdir, WshShell
caption = "InstallerDemoService.Setup"
curdir = Session.Property("CustomActionData")
Set WshShell = CreateObject ("WScript.Shell")
WshShell.Run ("notepad.exe """ +
curdir + "\InstallerDemoService.exe.config""")
Extra functionality
In the script that is run, anything can be done. In the demo code a question is asked whether or not to start the .NET Windows Service after installing. After answering 'Yes' the service will be started from the script.
Points of interest
In the VBScript the current directory is needed. Since a script within an installer package runs in its own scripting engine context, a vbs call to determine the path will not work (CreateObject("Scripting.FileSystemObject")
). The solution is to pass the target directory in the single parameter that is available from the installer to the script:
curdir = Session.Property("CustomActionData")
Conclusion
Using VBScript to enhance a setup and deployment project is easy to do and can be used for various tasks. I think it is an original way to extend an installer in this way.