using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
namespace RecycleApplicationPool
{
class Program
{
static void Main(string[] args)
{
string appPoolName = "DefaultAppPool";
string machineName = "LOCALHOST";
if (args.Length > 0)
appPoolName = args[0];
if (args.Length > 1)
machineName = args[1];
string error = null;
DirectoryEntry root = null;
try
{
Console.WriteLine("Restarting Application Pool " + appPoolName + " on " + machineName + "...");
root = new DirectoryEntry("IIS://" + machineName + "/W3SVC/AppPools/" +appPoolName);
Console.WriteLine(root.InvokeGet("Name"));
root.Invoke("Recycle");
Console.WriteLine("Application Pool recycling complete...");
}
catch(Exception ex)
{
error = "Error: Unable to access AppPool: " + ex.Message;
}
if ( !string.IsNullOrEmpty(error) )
{
Console.WriteLine(error);
return;
}
}
}
}
http://codepaste.net/5afgf6
Refer : http://weblog.west-wind.com/posts/2012/Oct/02/A-tiny-Utility-to-recycle-an-IIS-Application-Pool
Comments
Post a Comment