Extending Nullsoft Installer to talk to IIS

June 30, 2010

Talk to IIS from a Nullsoft Installer

A new Nullsoft installer plug-in provides access to IIS during an installation

Summary

An example of how the the Nullsoft installer plug-in, NsisIIS (http://nsis.sourceforge.net/NsisIIS_plug-in) , allows you to read from the IIS metabase when your installer is run.

Manipulating IIS from NSIS

One of the things we use the Nullsoft Installer (aka NSIS) is to deploy IIS based intranet applications. Just recently I’ve found a new IIS plug-in, NsisIIS which allows you to (in the authors words)

“to create/edit/delete/getinfo Microsoft IIS virtual directories and manage it’s service status”

I’ve often wished for just such a plug-in so I was really pleased to find someone had written it for me !

Sample Script

As soon as I saw this it seemed like a great idea. Unfortunately the current release doesn’t include any sample scripts (or it does I can’t find them) so I’ve written one.

My sample script, NSI_GetVirDirExample.nsi, dumps the details of a hard-coded virtual directory to the details panel of the installer like this :

NsisIIS Example Script

NsisIIS Example Script

The script that produces this output is a very simple NSIS script which looks like this (I’ve also made it available at http://pastie.org/1024393 to help with copy/pasting).

;This Nullsoft Installer System (NSIS) script illustrates
;the use of the NsisIIS plugin at version 1.0.0
;(http://nsis.sourceforge.net/NsisIIS_plug-in)
;
;This script uses a hardcoded virtual directory
;present in the default web site within IIS and
;dumps some configuration details to the NSIS
;details panel

;Output file name
OutFile "NSI_GetVDirExample.exe"
;'Show Details' panel open by default
ShowInstDetails show
section -
 ;variable to contain Virtual Directory name
 Var /GLOBAL vdName
 ;initialise to name of Virtual Directory of Interest
 StrCpy $vdName "DRS"
 ;warn the user what Virtual Directory they're pointing at
 ;because you end up with a very ugly crash if it doesn't exist
 MessageBox MB_OK "You are reviewing the details of Virtual Directory : $vdName ."

 ;call the GetVDir function from the NsisIIS plugin
 ;Registers are updated as follows:
 ;$0 Physical Path
 ;$1 Application Pool
 ;$2 Access Flags
 ;$3 Default Documents in comma delim list
 ;$4 IP Security Details
 ;$5 SSL Details (not working in this release)
 ;
 ;See NsisIIS documentation for more details
 NsisIIS::GetVDir $vdName

 ;dump the Virtual Directory config details from registers
 ;$0 to $5 out the the details panel
 DetailPrint "Config Details for Virtual Directory : $vdName"
 DetailPrint "Physical Path :$0"
 DetailPrint "App Pool :$1"
 DetailPrint "Access Flags :$2"
 DetailPrint "Default Docs :$3"
 DetailPrint "IP Security :$4"
 DetailPrint "SSL Flags :$5"
sectionend

Warnings !

Hardcoded Virtual Directory Name

To use my example script yourself you’ll need to amend the line which initialises the variable containing the virtual directory name, for instance if your virtual directory is called “Accounts” you would need to amend :

 StrCpy $vdName "DRS"

to read

 StrCpy $vdName "Accounts"

Error Handling

There’s no error handling in my example script (as you can see). If you specify a virtual directory that doesn’t exist or that you’re not allowed to access when you run NSI_GetVDirExample.exe it will crash and burn.

Default Web Site

As far as I can tell NsisIIS will only access the default web site. For 95% of IIS users that would be just fine but if you have a virtual directory on a non-default website you’re going to have to wait for a later release

NsisIIS Documentation

To take this any further you’ll want to read the documentation which you can find in a Word For Windows document here.

Leave a Reply