Reputation:
Nearly finished with my project, however I can't seem to be able to get the final section working:
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.
Upvotes: 0
Views: 593
Reputation: 767
Can try this one
var directoryEntry = new DirectoryEntry(APPLICATION_POOL_URL, USERNAME, PASSWORD);
// call to stop the Application Pool
directoryEntry.Invoke("Stop", null);
// call to start the Application Pool
directoryEntry.Invoke("Start", null);
// call to recycle the Application Pool
directoryEntry.Invoke("Recycle", null);
Basically you have to call
directoryEntry.Invoke("Stop/Start/Recycle", null);
Upvotes: 2