Click here to Skip to main content
12,891,744 members (53,658 online)
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 24 Sep 2005

Using VBScript in an installer package

, 24 Sep 2005
Rate this:
Please Sign up or sign in to vote.
How to use VBScript to enhance an installer package and guide the user through installation and configuration.


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.


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"
'Determine the path where this running script is. 
'That is also the path to the config-file.
'The path ("[TARGETDIR]") is being passed by the installer 
'in the one available parameter: CustomActionData
curdir = Session.Property("CustomActionData")

'Start Notepad with the config-file
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")


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.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Edwin Roetman
Web Developer
Satellite Provider Satellite Provider
Since 1995 I have gathered wide experience in IT, in several different roles and in different environments. I am currently working for Capgemini Netherlands as Microsoft Software Developer, Software Architect and Project Manager.
In my leisure time I like to do sports, mainly speedskating and windsurfing. I also love to go cycling and to travel with my girlfriend and our son in camper.

You may also be interested in...


Comments and Discussions

AnswerRe: To Registry Pin
qumer10129-Sep-05 0:44
memberqumer10129-Sep-05 0:44 
GeneralRe: To Registry Pin
Edwin Roetman29-Sep-05 9:39
memberEdwin Roetman29-Sep-05 9:39 
GeneralRe: To Registry Pin
qumer10129-Sep-05 20:23
memberqumer10129-Sep-05 20:23 
GeneralRe: To Registry Pin
_____11-Feb-09 7:18
member_____11-Feb-09 7:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 24 Sep 2005
Article Copyright 2005 by Edwin Roetman
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid