Previous Next

Thread: Programmatically restart IIS / worker process from console application

Last post 08-18-2008 3:37 PM by joelangley. 4 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (5 items)

Sort Posts:

  • 08-17-2008, 4:01 PM

    • bluekiwi
    • Not Ranked
    • Joined on 04-28-2005, 6:45 PM
    • Posts 2

    Programmatically restart IIS / worker process from console application

    Hi,

    How to:

    • Programmatically restart IIS
    • Programmatically restart the worker process
    From a console application (C# or VB).

     

  • 08-17-2008, 4:24 PM In reply to

    • mukhtard
    • Top 25 Contributor
    • Joined on 07-07-2008, 9:13 PM
    • Redmond, WA
    • Posts 165

    Re: Programmatically restart IIS / worker process from console application

    You want to make a call to iisreset.

    Thanks,
    Mukhtar Desai
    IIS Performance Team

  • 08-17-2008, 4:40 PM In reply to

    Re: Programmatically restart IIS / worker process from console application

    You can stop and start the IIS App Pool by using the DirectoryEntry ... Not sure of the full syntax to get to the app pools  but it is possible

  • 08-18-2008, 3:27 PM In reply to

    • bluekiwi
    • Not Ranked
    • Joined on 04-28-2005, 6:45 PM
    • Posts 2

    Re: Programmatically restart IIS / worker process from console application

    Is there a code sample?

  • 08-18-2008, 3:37 PM In reply to

    Re: Programmatically restart IIS / worker process from console application

    http://www.codeproject.com/KB/cs/Start_Stop_IIS_Website.aspx

    or (from http://kadnan.com/blog/2005/02/15/diplay-iis-hosted-site-names-in-c/) :

    try
    {
    const string WebServerSchema = “IIsWebServer”; // Case Sensitive
    string ServerName = “SIDDIQI”;
    DirectoryEntry W3SVC = new DirectoryEntry(”IIS://” + ServerName + “/w3svc”, “Domain/UserCode”, “Password”);
    foreach (DirectoryEntry Site in W3SVC.Children)
    {

    if (Site.SchemaClassName == WebServerSchema)
    {
    //Console.WriteLine(Site.Name + ” - ” + Site.Properties[”ServerComment”].Value.ToString());
    }
    }
    }
    // Catch any errors
    catch (Exception e)
    {
    Console.WriteLine(”Error: ” + e.ToString());
    }

     

Page 1 of 1 (5 items)
Page view counter