Nearly finished with my project, however I can't seem to be able to get the final section working:
- Fetch all Application Pools on the server.
- Loop through all directories of the application pools until I find a match.
- Restart the matching application pool.
That's all I'm trying to do, however I can't get it working. The code I have managed to drag together so far, only returns a list of the application pool names:
public static string[] FetchAppPools()
{
List<string> lvAppPools = new List<string>();
DirectoryEntry lvWebService = new DirectoryEntry("IIS://localhost/W3SVC");
IEnumerator ie = lvWebService.Children.GetEnumerator();
DirectoryEntry lvServer = null;
while(ie.MoveNext())
{
lvServer = (DirectoryEntry)ie.Current;
if (lvServer.SchemaClassName == "IIsWebServer")
lvAppPools.Add(lvServer.Properties["ServerComment"][0].ToString());
}
return lvAppPools.ToArray();
}
How would I need to change the above code to also bring me back the directories associated with each of the application pools (C:\inetpub\Website1)?
Thank you.