// 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 ");
}
}