62,046
社区成员
发帖
与我相关
我的任务
分享
string method="Start"; //Start开启 Recycle回收 Stop 停止
string AppPoolName = "chengxuchiname";
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("应用程序池名称启动成功","启动成功");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"启动失败");
}
//获取应用程序池列表 等操作
/// <summary>
/// 获取应用程序池->数组
/// </summary>
/// <returns></returns>
public ApplicationPool[] GetApplicationPools()
{
if ((SiteInfo.ServerType != WebServerTypes.IIS6) && (SiteInfo.ServerType != WebServerTypes.IIS7)) return null;
DirectoryEntry directoryEntry = GetDirectoryEntry("IIS://LOCALHOST/W3SVC/AppPools");
if (directoryEntry == null) return null;
List<ApplicationPool> list = new List<ApplicationPool>();
foreach (DirectoryEntry entry2 in directoryEntry.Children)
{
PropertyCollection properties = entry2.Properties;
ApplicationPool pool = new ApplicationPool();
pool.Name = entry2.Name;
list.Add(pool);
}
return list.ToArray();
}
/// <summary>
/// 应用程序池
/// </summary>
public class ApplicationPool
{
/// <summary>
/// 版本
/// </summary>
public string DotNetVersion = "v2.0.50727";
/// <summary>
/// 应用程序池名
/// </summary>
public string Name = "";
}
ApplicationPool[] AppPools = IISHelper.GetApplicationPools();
foreach (ApplicationPool pool in AppPools)
...{
Console.WriteLine(pool.Name);
}
/**//// <summary>
/// 获取应用程序池->数组
/// </summary>
/// <returns></returns>
public ApplicationPool[] GetApplicationPools()
...{
if ((SiteInfo.ServerType != WebServerTypes.IIS6) && (SiteInfo.ServerType != WebServerTypes.IIS7)) return null;
DirectoryEntry directoryEntry = GetDirectoryEntry("IIS://LOCALHOST/W3SVC/AppPools");
if (directoryEntry == null) return null;
List<ApplicationPool> list = new List<ApplicationPool>();
foreach (DirectoryEntry entry2 in directoryEntry.Children)
...{
PropertyCollection properties = entry2.Properties;
ApplicationPool pool = new ApplicationPool();
pool.Name = entry2.Name;
list.Add(pool);
}
return list.ToArray();
}
/**//// <summary>
/// 应用程序池
/// </summary>
public class ApplicationPool
...{
/**//// <summary>
/// 版本
/// </summary>
public string DotNetVersion = "v2.0.50727";
/**//// <summary>
/// 应用程序池名
/// </summary>
public string Name = "";
}