Created
May 19, 2016 07:39
-
-
Save johnsonz/47c5be1dfef52ba8da9fdfcc93ff3990 to your computer and use it in GitHub Desktop.
C#重启IIS Application Pool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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