C # start collection of IIS website application pool

Source: Internet
Author: User

// Add application pool space reference
Using system. directoryservices;
Using system. text;
Using system. Text. regularexpressions;
Using system. diagnostics;
Using system. Management;

Private void button6_click (Object sender, system. eventargs E)
{
// If the application pool does not exist, the system will report an error and the specified path cannot be found.
String apppoolname = This. textbox1.text. Trim ();
String method = "start ";

Try
{
Directoryentry apppool = new directoryentry ("IIS: // localhost/w3svc/apppools ");
Directoryentry findpool = apppool. Children. Find (apppoolname, "iisapplicationpool ");
Findpool. Invoke (method, null );
Apppool. commitchanges ();
Apppool. Close ();
MessageBox. Show ("application pool name started successfully", "started successfully ");
}
Catch (exception ex)
{
MessageBox. Show (ex. message, "startup failed ");
}

}

Private void button7_click (Object sender, system. eventargs E)
{
// If the current status of the application pool is stopped, an exception is reported.
String apppoolname = This. textbox1.text. Trim ();
String method = "recycle ";

Try
{
Directoryentry apppool = new directoryentry ("IIS: // localhost/w3svc/apppools ");
Directoryentry findpool = apppool. Children. Find (apppoolname, "iisapplicationpool ");
Findpool. Invoke (method, null );
Apppool. commitchanges ();
Apppool. Close ();
MessageBox. Show ("application pool name recycling successful", "recycling successful ");
}
Catch (exception ex)
{
MessageBox. Show (ex. message, "failed to recycle ");
}
}

Private void button8_click (Object sender, system. eventargs E)
{
String apppoolname = This. textbox1.text. Trim ();
String method = "stop ";

Try
{
Directoryentry apppool = new directoryentry ("IIS: // localhost/w3svc/apppools ");
Directoryentry findpool = apppool. Children. Find (apppoolname, "iisapplicationpool ");
Findpool. Invoke (method, null );
Apppool. commitchanges ();
Apppool. Close ();
MessageBox. Show ("application pool name stopped successfully", "stopped successfully ");
}
Catch (exception ex)
{
MessageBox. Show (ex. message, "Stop failed ");
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.