4

We have a web application that until now installed under the "Default Web Site" in IIS. A customer now wants us to install it under a different web site, and we want to do that from the installer. My question is in 2 parts: A) How do I programatically add another web site alongside the 'default web site'? B) We are using Windows Installer - is there a way to trigger whatever code I write for section A from within the installer in time for the installation to take place at the new location? It looks like overriding Install() is too late in the game...

Eran Rehavi
  • 101
  • 1
  • 9

4 Answers4

3

we use a js windows script to update our virtual directories between branches, I would imagine that you could use the same objects to create a website

var iisPath = "IIS://localhost/W3SVC/" + siteID;
var site = GetObject(iisPath);

Microsoft has a fairly extensive article on configuring IIS 6 programatically. As long as your MSI can call a batch file, this article should help out.

This article also has a complete script file that creates a website.

Jeff Martin
  • 10,812
  • 7
  • 48
  • 74
  • I guess I assumed that the website was C# not the requested Program. However, there is no reason these objects can't be used in C#. – Jeff Martin Jun 18 '09 at 15:24
2

Here's some C# code for programmatically creating a site:

1    using System.DirectoryServices;
 2    using System;
 3    
 4    public class IISAdmin
 5    {
 6       public static int CreateWebsite(string webserver, string serverComment, string serverBindings, string homeDirectory)
 7       {
 8          DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/w3svc");
 9          
 10         //Create a website object array
 11         object[] newsite = new object[]{serverComment, new object[]{serverBindings}, homeDirectory};
 12         
 13         //invoke IIsWebService.CreateNewSite
 14         object websiteId = (object)w3svc.Invoke("CreateNewSite", newsite);
 15         
 16         return (int)websiteId;
 17      
 18      }
 19   
 20      public static void Main(string[] args)
 21      {
 22         int a = CreateWebsite("localhost", "Testing.com", ":80:Testing.com", "C:\\inetpub\\wwwroot");
 23         Console.WriteLine("Created website with ID: " + a);
 24      }
 25      
 26   }

reference: http://www.it-notebook.org/iis/article/cs_create_website_iis6.htm

Ryan Shripat
  • 5,574
  • 6
  • 49
  • 77
1

If you're using WiX to create your MSI, see this question.

Community
  • 1
  • 1
Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
0

Not really an expert at MSI files, but you can add a website through scripting using adsutil.vbs. Poor man's way to handle this is to have your installer drop the files at a location without creating a website then run a later step with the script to create a website with the root at this location. Bonus points for making this optional for nudgy IIS admins like myself who hate installers touching IIS at all.

Wyatt Barnett
  • 15,573
  • 3
  • 34
  • 53