Skip to content

Instantly share code, notes, and snippets.

@johnsonz
Created May 19, 2016 07:39
Show Gist options
  • Save johnsonz/47c5be1dfef52ba8da9fdfcc93ff3990 to your computer and use it in GitHub Desktop.
Save johnsonz/47c5be1dfef52ba8da9fdfcc93ff3990 to your computer and use it in GitHub Desktop.
C#重启IIS Application Pool
private void StopAppPool(string AppPoolName, string method)
{
try
{
//1: Starting
//2: Started
//3: Stopping
//4: Stopped
//5: Pausing
//6: Paused
//7: Continuing
DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
DirectoryEntry findPool = appPool.Children.Find(AppPoolName, "IIsApplicationPool");
string state = findPool.Properties["AppPoolState"].Value.ToString();
findPool.Invoke("Stop", null);
appPool.CommitChanges();
appPool.Close();
WriteLog(1, LogName, "Stop App Pool Success");
}
catch (Exception ex)
{
WriteLog(-1, LogName, "Stop App Pool Failure" + " Message:" + ex.Message);
}
}
private void StartAppPool(string AppPoolName, string method)
{
try
{
//1: Starting
//2: Started
//3: Stopping
//4: Stopped
//5: Pausing
//6: Paused
//7: Continuing
DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
DirectoryEntry findPool = appPool.Children.Find(AppPoolName, "IIsApplicationPool");
string state = findPool.Properties["AppPoolState"].Value.ToString();
findPool.Invoke("Start", null);
appPool.CommitChanges();
appPool.Close();
WriteLog(1, LogName, "Start App Pool Success");
}
catch (Exception ex)
{
WriteLog(-1, LogName, "Start App Pool Failure" + " Message:" + ex.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment