Search code examples
c#asp.netiis-6windows-installerinstallation

Enable ASP.NET in IIS6 Programmatically


Is there a way to enable the ASP.NET Web Service Extension in IIS6 via C#? I'm trying to simplify a website setup program for people who haven't used IIS before.


Solution

  • Looking around all the examples of this are written in vbscript. So I cheated and came up with this function:

    static void EnableASPNET()
    {
        var file = "wmi.vbs";
        using (var writer = new StreamWriter(file))
        {
            writer.WriteLine("Set webServiceObject = GetObject(\"IIS://localhost/W3SVC\")");
            writer.WriteLine("webServiceObject.EnableWebServiceExtension \"ASP.NET v2.0.50727\"");
            writer.WriteLine("webServiceObject.SetInfo");
        }
        var process = Process.Start("cscript", file);
        process.WaitForExit();
        File.Delete(file);
    }