locked
Delete a IIS application pool through Microsoft.SharePoint namespace RRS feed

  • Question

  • Hi everybody.

    I'm creating web applications programmatically remotely... and now i would like to delete them... completely. I use the SPWebApplication.Delete method to do this and it works well. However, this method doesn't delete the associated content databases and IIS application pool.

    My problem: i would like to delete the associated application pool but the SPApplicationPool.Delete method just delete the reference (in the MOSS database, i guess), but not the app pool in IIS.

    So, my question is: is there a way in the Microsoft.SharePoint namespace to really delete an IIS app pool ? Or another way ?...

    I've seen the Microsoft.Web.Administration namespace, but if i've well understood, it seems to work only on IIS 7... And because I've got farms that runs both under IIS 6 and IIS 7, i would like to avoid to create a different tool for each version of IIS!

    Thanks a lot,
    Max

    PS: please excuse my english, it's not my mother's tongue ;)
    Wednesday, October 28, 2009 3:05 PM

Answers

  • I don't think this is a good idea- the application pool could be shared by several SP web apps or even be used within IIS...

    If you are absolutely sure you could call the deletion-process on a commandline


    %winnt%\systen32\inetsrv\appcmd  delete apppool /apppool.name: [appname] 
    • Proposed as answer by Markus I_ Wednesday, October 28, 2009 3:53 PM
    • Marked as answer by Maxime G Thursday, October 29, 2009 9:04 AM
    Wednesday, October 28, 2009 3:09 PM
  • Very nice, it works.

    The exact command is %windir %\system32\inetsrv\appcmd delete apppool /apppool.name:[appPool]

    I can launch it remotely thanks to the Win32_Process class... but it only works on IIS 7 .

    Does anyone know a equivalent on IIS 6 ?

    Thanks,
    Max
    • Proposed as answer by Markus I_ Wednesday, October 28, 2009 3:53 PM
    • Marked as answer by Maxime G Thursday, October 29, 2009 9:04 AM
    Wednesday, October 28, 2009 3:46 PM
  • Hi.

    I've succeeded following your way... but translating it in C# ;) (easier for me). The code:

    string myAppPoolName = "myAppPool";
    string iisPath = "IIS://{0}/W3SVC/AppPools"
    DirectoryEntry rootEntry = new DirectoryEntry(string.Format(iisPath, Environment.MachineName));
    if (rootEntry != null) {
    	DirectoryEntry tempEntry = null;
    	foreach (DirectoryEntry Entry in rootEntry.Children) {
    		if (Entry.Name.Equals(myAppPoolName, StringComparison.InvariantCultureIgnoreCase)) {
    			tempEntry = Entry;
    		}
    	}
    	if (tempEntry != null) {
    		tempEntry.DeleteTree();
    
    	}
    }

    It works both on IIS 6 and IIS 7.

    Thanks Markus for your precious help.

    Regards,
    Max
    • Edited by Maxime G Thursday, October 29, 2009 9:03 AM Text formatting
    • Marked as answer by Maxime G Thursday, October 29, 2009 9:04 AM
    Thursday, October 29, 2009 9:02 AM

All replies

  • I don't think this is a good idea- the application pool could be shared by several SP web apps or even be used within IIS...

    If you are absolutely sure you could call the deletion-process on a commandline


    %winnt%\systen32\inetsrv\appcmd  delete apppool /apppool.name: [appname] 
    • Proposed as answer by Markus I_ Wednesday, October 28, 2009 3:53 PM
    • Marked as answer by Maxime G Thursday, October 29, 2009 9:04 AM
    Wednesday, October 28, 2009 3:09 PM
  • Thanks, i'm gonna try it right now !

    And for sure it's for dedicated pools only ;)
    Wednesday, October 28, 2009 3:31 PM
  • Very nice, it works.

    The exact command is %windir %\system32\inetsrv\appcmd delete apppool /apppool.name:[appPool]

    I can launch it remotely thanks to the Win32_Process class... but it only works on IIS 7 .

    Does anyone know a equivalent on IIS 6 ?

    Thanks,
    Max
    • Proposed as answer by Markus I_ Wednesday, October 28, 2009 3:53 PM
    • Marked as answer by Maxime G Thursday, October 29, 2009 9:04 AM
    Wednesday, October 28, 2009 3:46 PM
  • You can write a simple VBS prog for accessing the IIS object model


    dim obj = GetObject("IIS://" & "myMachineName"& "/W3SVC/apppools")
    obj.delete "IIsApplicationPool",apppoolname

    Wednesday, October 28, 2009 3:53 PM
  • Hi.

    I've succeeded following your way... but translating it in C# ;) (easier for me). The code:

    string myAppPoolName = "myAppPool";
    string iisPath = "IIS://{0}/W3SVC/AppPools"
    DirectoryEntry rootEntry = new DirectoryEntry(string.Format(iisPath, Environment.MachineName));
    if (rootEntry != null) {
    	DirectoryEntry tempEntry = null;
    	foreach (DirectoryEntry Entry in rootEntry.Children) {
    		if (Entry.Name.Equals(myAppPoolName, StringComparison.InvariantCultureIgnoreCase)) {
    			tempEntry = Entry;
    		}
    	}
    	if (tempEntry != null) {
    		tempEntry.DeleteTree();
    
    	}
    }

    It works both on IIS 6 and IIS 7.

    Thanks Markus for your precious help.

    Regards,
    Max
    • Edited by Maxime G Thursday, October 29, 2009 9:03 AM Text formatting
    • Marked as answer by Maxime G Thursday, October 29, 2009 9:04 AM
    Thursday, October 29, 2009 9:02 AM