Home > Installation, MS CRM > Creating virtual directories\IIS applications in InstallShield 2008

Creating virtual directories\IIS applications in InstallShield 2008

There is a well-known issue with InstallShield 2008 creating IIS-structure.

The first bad thing in using standard functional of IS (InstallShield) is that it always creates Application on top of every virtual directory, even if you have left a field for application to be blank.

The second is that IS translates application name (if it is really needed) incorrectly. For example, if your application name is stored in String Property named {IIS_VAPP_NAME} and you will see something like this:  {IIS_VAPP_NAME} MyApplication in text box before editing it, then you probably suppose that application will be created with name MyApplication. But its name will be .. “{IIS_VAPP_NAME} MyApplication”.

The third –  if you need to install your site under already existing solution (for example, in ISV virtual folder under Microsoft Dynamics CRM site as in my case), then you’ll need to “create” already existing folder (and it will become application due to the first mentioned IS “feature”) and on uninstall or rollback it will be deleted as configurable object from IIS metabase. Unpleasant, isn’t it?

I really don’t know if more recent versions of IS have these bugs, so this article for those, who has to struggle with InstallShield 2008, like me.

So, what we can do? Solution I recommend is using custom script action(s) for creating IIS infrastructure as it is needed by project. 

Let’s start from a script for creating virtual directories. My example is written in VBScript and it creates either IIS application or virtual directory with anonymous access. If you don’t need anonymous access it is easy to make changes to script. So here it is:

Sub CreateVDir(ParentVDir,Name,Path, blnIsApplication)
    On Error Resume Next
    Set objIIS = GetObject(ParentVDir & "/" & Name)
    If Err.Number <> 0 Then
        Set objIIS = Nothing
        Set objIIS = GetObject(ParentVDir)

        Set objVirtualDirectory = objIIS.Create("IISWebVirtualDir", Name)objVirtualDirectory.AccessScript = TrueobjVirtualDirectory.Path = Path objVirtualDirectory.AccessWrite = TrueobjVirtualDirectory.AccessRead = TrueobjVirtualDirectory.AccessExecute = True
        If Not blnIsApplication Then
                'comment or delete if Anonymous access is not neededobjVirtualDirectory.AuthAnonymous =TrueobjVirtualDirectory.AnonymousUserName=strOwner objVirtualDirectory.AnonymousPasswordSync=True
        ElseobjVirtualDirectory.AppCreate blnInProcessApplication objVirtualDirectory.AppCreate (True)
        End IfobjVirtualDirectory.SetInfo End If

End Sub

Dim strVirtualDirectoryName 'IIS Virtual Directory Name
Dim blnInProcessApplication 'IIS In Process Application Flag
Dim objIIS 'ADSI IIS Object
Dim strVirtualDirectoryPath 'IIS Virtual Directory Path
Dim objFileSystem 'VBScript FileSystemObject
Dim strOwner 'NT Folder Owner
Dim objVirtualDirectory 'ADSI IIS Virtual Directory Object
Dim blnScriptPermissions 'IIS script permissions flag
Dim blnExecutePermissions ' IIS Execute permissions flag
Dim blnWritePermissions ' 
Dim blnReadPermissions '
Dim strHTTPReferer 'IIS Referrer Page
Dim objWSH 'Windows Scripting Host Object
Dim objRTC 'Return
Dim strACLCommand 'Command Line string to set ACLs
Dim MachineName ' computer name
Dim InstallDir Dim IISSiteNumber Dim strParentVDir Dim strName InstallDir = Session.Property("INSTALLDIR")IISSiteNumber = Session.Property("TEMP_IISSITENUMBER")strOwner = "IUSR_" & Replace( Session.Property("HOSTNAME"), "http://","")

'wsc.Popup "Setting Permissions for Computer Name = " & strOwner , 1blnScriptPermissions = "True"blnExecutePermissions = "True"blnWritePermissions = "True"blnReadPermissions = "True"
'Create IncadeaCVRMstrVirtualDirectoryPath = InstallDir & "\MyApplication"strParentVDir = "IIS://localhost/W3SVC/" & IISSiteNumber & "/Root/ISV"strName = "MYApplication"CreateVDir strParentVDir,strName,strVirtualDirectoryPath, True

'Create Services folderstrParentVDir = strParentVDir & "/" & strName strName = "Services"strVirtualDirectoryPath = strVirtualDirectoryPath & "\" & strName CreateVDir strParentVDir,strName,strVirtualDirectoryPath, False

 As an example, I create an application named MyApplication under existing ISV folder of my MS Dynamics CRM deployment. Then I create a virtual folder Services under my newly created application. As you can see, I use some preset IS properties: [INSTALLDIR], [TEMP_IISSITENUMBER], [HOSTNAME] to exchange with IS project. You may create your own properties for all needed configuration and use them in script action as well.

This script must be put in a new custom action of type “VBScript custom action” with properties like on screenshot below (pay attention to the selected ones):

Its place in sequence is under Execute path, anywhere after InstallFiles action.

So, half of work is done. But what about uninstall? Since it is custom action, IS will not know how to uninstall it. Let’s write just one more script for DeleteVirtualDirectories action:

strParentVDir = "IIS://localhost/W3SVC/" & Session.Property("TEMP_IISSITENUMBER") & "/Root/ISV"
Set objIIS = GetObject(strParentVDir)
On Error Resume NextobjIIS.Delete "IISWebVirtualDir", "MyApplication"

On Error Resume Next
While Err.Number = 0
Set objIIS1 = GetObject(strParentVDir & "/MyApplication")

 So, it locates our application, deletes it and waits untill trying to get virtual directory’s object will throw an error, wich will mean that it had been deleted.

Custom action, containing uninstallation script, must be created like an action for creating except for its property “Install Exec Condition” is blank and “Return Process” equals to “Synchronous (Ignores exit code)”. In sequence it must be placed just before CreateVirtualDirectories action (previously created). In that way, any install/uninstall process will try to execute DeleteVirtualDirectories (if virtual directories don’t exist it will throw error, but installation process will not stop as soon as we’ve set to ignore exit code of action) and then to execute CreateVirtualDirectories, but only if it is not REMOVE process.

 Hope, it will help with your installation 😉

  1. Kevin
    21.06.2011 at 15:01

    Part of the code is being cut off. I fixed this by selecting text past the code, copying it into Notepad++, and deleting the extra stuff I copied.

    Also, the commenting seems to be off on the last three lines; what should it actually say?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: