We'll run these cmds during install :
appcmd add apppool /name:MyApp /managedPipelineMode:Integrated /processModel.identityType:NetworkService /processModel.idleTimeout:01:00:00
appcmd add app /site.name:"Default Web Site" /path:/MyApp /physicalPath:"c:\inetpub\wwwroot\myapp" /applicationPool:MyApp
appcmd set config "Default Web Site/MyApp" /section:anonymousAuthentication /enabled:true /commit:AppHost
Then on an uninstall we do this :
appcmd delete app "Default Web Site/MyApp"
appcmd delete apppool MyApp
After the install, the anonymousAuthentication section is added to the applicationHost.config file, as expected. However, after uninstall, the anonymousAuthentication section is still in the applicationHost.config file. If I run the setup, but then manually delete the application via the IIS mgmt console, the anonymousAuthentication section (actually, the entire MyApp location section) is removed. I would have expected the "appcmd delete app" to remove the MyApp location section from the applicationHost.config file, but it doesn't.
I also tried the "appcmd clear config /section:anonymousAuthentication /delete /commit:AppHost" but I get a "the data is invalid" error.