xxxxプログラマのメモ

先人に感謝と敬意

Applicationpool #アプリケーションプール

ApplicationPool.State Property (Microsoft.Web.Administration)
How to get the name and status of all application pools in IIS7 in C#? - CodeProject
Get a list of App Pools and their Associated Identity with C# : The Official Microsoft IIS Forums

ServerManager server = new ServerManager();

ApplicationPoolCollection applicationPools = server.ApplicationPools;
foreach (ApplicationPool pool in applicationPools)
{
//get the AutoStart boolean value
bool autoStart = pool.AutoStart;

//get the name of the ManagedRuntimeVersion
string runtime = pool.ManagedRuntimeVersion;

//get the name of the ApplicationPool
string appPoolName = pool.Name;

//get the identity type
ProcessModelIdentityType identityType = pool.ProcessModel.IdentityType;

//get the username for the identity under which the pool runs
string userName = pool.ProcessModel.UserName;

//get the password for the identity under which the pool runs
string password = pool.ProcessModel.Password;
}

// If the applicationPool is stopped, restart it.
if (applicationPool.State == ObjectState.Stopped)
{
applicationPool.Start();
}

public static string GetApplicationPoolNames()
{
ServerManager manager = new ServerManager();
string status;
//string DefaultSiteName = System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName();
//Site defaultSite = manager.Sites[DefaultSiteName];
string appVirtaulPath = HttpRuntime.AppDomainAppVirtualPath;
string mname = System.Environment.MachineName;
string appPoolName = string.Empty;
manager = ServerManager.OpenRemote(mname);
ObjectState result = ObjectState.Unknown;

ApplicationPoolCollection applicationPoolCollection = manager.ApplicationPools;

foreach (ApplicationPool applicationPool in applicationPoolCollection)
{
//result = manager.ApplicationPools[applicationPool].State;
string resudlt = applicationPool.Name;
Console.WriteLine("State : " + resudlt);

}

return appPoolName;
}

Thanks!