I have a simple C# app that is used to install and configure our web services. Part of this involves setting the app pool identity property with command-line args that are fed to the installer. To achieve this, I'm using the following code in a custom action:
using (System.DirectoryServices.DirectoryEntry appPools = new System.DirectoryServices.DirectoryEntry("IIS://Localhost/W3SVC/AppPools"))
{
System.DirectoryServices.DirectoryEntry myAppPool = appPools.Children.Find("SomeAppPool", "IIsApplicationPool");
myAppPool.Properties["AppPoolIdentityType"].Value = 3;
myAppPool.Properties["WAMUserName"].Value = "SomeUserName";
myAppPool.Properties["WAMUserPass"].Value = "SomePassword";
myAppPool.Invoke("SetInfo", null);
myAppPool.CommitChanges();
}
We've found that on newer machines, this code will error with a COM Exception 0x80005000
unless the
"IIS Metabase and IIS 6 configuration compatablility"
feature is installed (i.e. "Control Panel->Programs and Features->Turn Windows features on or off->Internet Information Services->Web Management Tools->IIS 6 Management Compatibility->IIS 6 Metabase and IIS 6 configuration compatibility"
must be enabled).
Since this method of updating an app pool identity seems to have been dropped after IIS 6, does this mean that there is a newer or more modern way of updating the Identity property of an IIS app pool? I've Googled this pretty extensively, and using the System.DirectoryServices.DirectoryEntry namespace seems to be the only way I can find to set an app pool identity programmatically with C#.
I can use this code and require the "IIS Metabase and IIS 6 configuration compatablility"
to be installed, but if this code is deprecated in favor of a newer method, then I'd rather just use the newer method.
User contributions licensed under CC BY-SA 3.0