Click here to Skip to main content
Click here to Skip to main content
Go to top

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.

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"
'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")

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.

License

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

Share

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.

Comments and Discussions

 
QuestionHow to run VB script before Installation PinmemberSumanta Rout13-Nov-07 4:11 
AnswerRe: How to run VB script before Installation PinmemberEdwin Roetman13-Nov-07 9:03 
QuestionWhy WSH? PinmemberRichard Deeming29-Sep-05 4:26 
AnswerRe: Why WSH? PinmemberEdwin Roetman29-Sep-05 9:28 
GeneralRe: Why WSH? PinmemberRichard Deeming29-Sep-05 22:49 
GeneralRe: Why WSH? PinmemberEdwin Roetman30-Sep-05 9:19 
GeneralRe: Why WSH? PinmemberCasp9-May-07 2:32 
GeneralRe: Why WSH? PinmemberRichard Deeming9-May-07 5:29 
GeneralTo Registry Pinmemberqumer10128-Sep-05 1:31 
QuestionRe: To Registry PinmemberEdwin Roetman28-Sep-05 11:06 
AnswerRe: To Registry Pinmemberqumer10129-Sep-05 0:44 
GeneralRe: To Registry PinmemberEdwin Roetman29-Sep-05 9:39 
GeneralRe: To Registry Pinmemberqumer10129-Sep-05 20:23 
GeneralRe: To Registry Pinmember_____11-Feb-09 7:18 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 24 Sep 2005
Article Copyright 2005 by Edwin Roetman
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid