March 25th, 2008IIS6, Creating Application Pools with .NET
I know this is VB.NET but i was in a hurry and my C# sucks
this is mostly cobbled togther from other stuff I found on the net, none of which did EXACTLY what I needed
When I get the time i will publish some of my other functions, including IIS6 site create and IIS6 FTP Profile Create
This is a simple VB.NET function to create and IIS6 Application pool
This function is designed to specify the UserId and Password for the AppPool Identity and was used in an environment where domain credentials were used
Function CreateAppPool(ByVal StrMachine As String, ByVal AppName As String, ByVal UserName As String, ByVal Password As String) As String
CreateAppPool = “success”
Dim foundapp As Boolean
Dim apppools As DirectoryEntries
Dim apppool2 As DirectoryEntry
Dim apppool As DirectoryEntry
Dim NewAppPool As Object
foundapp = False
apppool2 = New DirectoryEntry(“IIS://” & StrMachine & “/w3svc/AppPools”)
apppools = apppool2.Children
‘test for duplicate poolname
For Each apppool In apppools ‘ scan each current app pool for check its name
If UCase(apppool.Name) = UCase(AppName) Then ‘ no need to check class type as everything at this level is a AppPool
foundapp = True
End If
Next
If Not foundapp Then
‘create the APP Pool and set unique information, most of the data is inherited
NewAppPool = apppool2.Children.Add(AppName, “IIsApplicationPool”)
NewAppPool.Properties(“AppPoolIdentityType”).Item(0) = 3
NewAppPool.Properties(“WAMUserName”).Item(0) = UserName
NewAppPool.Properties(“WAMUserPass”).Item(0) = Password
NewAppPool.CommitChanges()
NewAppPool = Nothing
Else
CreateAppPool = “Duplicate AppPool found”
End If
apppool2 = Nothing
apppools = Nothing
End Function

May 3rd, 2008 at 20:34
thanks for the sample. Exactly what I’m trying to do!
November 12th, 2008 at 11:26
Hi, its a very much easy n working piece of code could u please help me while creating the new app pool i want to add apppool identity (username/password) same as default pool settings.
November 12th, 2008 at 12:02
Not something I have done, but http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e3a60d16-1f4d-44a4-9866-5aded450956f.mspx?mfr=true says these values can be set at the /LM/W3SVC key, which implies they can inherit, so simply removing the lines that setup the username and password should do what you need
it is also worth looking at http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e3a60d16-1f4d-44a4-9866-5aded450956f.mspx?mfr=true
which talks about the AppPoolIdentityType value
November 12th, 2008 at 12:12
Hi, its a very much easy n working piece of code could u please help me while creating the new app pool i want to add apppool identity as Network Service. How could i do it plz tell me. Plzz tell me the solution 4 both thanks alot.
November 12th, 2008 at 12:15
If Not foundapp Then
‘create the APP Pool and set unique information, most of the data is inherited
NewAppPool = apppool2.Children.Add(AppName, “IIsApplicationPool”)
NewAppPool.Properties(“AppPoolIdentityType”).Item(0) = 2
‘NewAppPool.Properties(“WAMUserName”).Item(0) = UserName
‘NewAppPool.Properties(“WAMUserPass”).Item(0) = Password
NewAppPool.CommitChanges()
NewAppPool = Nothing
Else
CreateAppPool = “Duplicate AppPool found”
End If
is it rite which i did
November 12th, 2008 at 12:18
Than a lot dear your links realy helped me alot.
U r great…………