Create website programmatically iis 6

how do i create a website programmatically in iis 6?
i am using vs 2005

is there any easy way to do this?

Here is something i want to configure on creation

website folder
description
application pool
asp.net version
host header
LVL 5
Darth_helgeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:

You can do all of that using the ADSI interface. There is only one slight problem with me describing it for you though, I don't do anything with VB, only VBScript.

Still, much of it is translatable sort of, I have some vague notes on C# versions of some of this somewhere, but that's probably not much help either.

That said... In some sort of order...

' Bindings (Host Header) get loaded into a collection initially, they're easy enough to alter later on but we
' need at least one to setup the site:

colBindings = Array(0)
Set colBindings(0) = objProvider.Get("ServerBinding").SpawnInstance_()
colBindings(0).IP = SERVER_IP
colBindings(0).Port = "80"
colBindings(0).Hostname = "www.test.com"

Set objProvider = objLocator.ConnectServer("<Server Name>", "root/MicrosoftIISv2")
Set objService = objProvider.Get("IIsWebService='W3SVC'")

strSiteObjectPath = objService.CreateNewSite("Site Description / Server Comment", colBindings, "C:\Path\To\Site")

' We're going to get the Metabase Path for the site from the string returned by the CreateNewSite method.
' Required to play around with some of it's settings.

Set objPath = CreateObject("WbemScripting.SWbemObjectPath")
objPath.Path = strSiteObjectPath
strSitePath = objPath.Keys.Item("")

' Re-connect to the site and set the properties

Set objSite = objProvider.Get("IIsWebServerSetting='" & strSitePath & "'")
Set objVirtualDirectory = objProvider.Get("IIsWebVirtualDirSetting='" & strSitePath & "/ROOT'")

' Application Pool Creation

Set objAppPools = GetObject("IIS://<Server Name>/W3SVC/AppPools")
Set objAppPool = objAppPools.Create("IIsApplicationPool", "<App Pool Name>")
Set objAppPool = Nothing
Set objAppPools = Nothing

' Assign the Pool to the Site

objVirtualDirectory.AppFriendlyName = strServerName
objVirtualDirectory.AppPoolID = strServerName
objVirtualDirectory.SetInfo

' If you need to rewrite Bindings they can be treated as an Array but it has to be done via ADSI not
' WMI / WBEM

objSite = GetObject("IIS://<Server Name>/" & strSitePath)
arrBindings = objSite.ServerBindings

' You now have an array of lines like this:
' SERVER_IP:HTTP_PORT:Domain_Name
' i.e. 192.168.1.1:80:www.test2.com
' If you want to add more just add them to the array and load it back in:

objSite.ServerBindings = arrBindings
objSite.SetInfo
0
Chris DentPowerShell DeveloperCommented:

This bit:

You can do all of that using the ADSI interface.

Should have said:

You can do all of that using the ADSI and WMI interfaces.
0
Darth_helgeAuthor Commented:
thank you but how do you choose which asp.net version to use? i can't see that in your code
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Chris DentPowerShell DeveloperCommented:

Oh sorry, forgot to mention that. They only brought that in with ASP.Net 2.0, I just haven't had a chance to look where it's stored yet. I'll have a dig around the metabase this afternoon, doesn't matter if I break it on my machine ;)

Chris
0
Chris DentPowerShell DeveloperCommented:

Okay changing between the two different ASP.NET versions is pretty easy. You basically have to alter all the ScriptMaps it has in place, the application configuration in effect. The disadvantage is you have to check the version numbers that are being used.

This shows how you could switch from one to the other:

objSite = GetObject("IIS://<Server Name>/" & strSitePath)

' Change from 2.0 to 1.1

arrScriptMaps = objSite.ScriptMaps
For i = 0 to UBound(arrScriptMaps)
      If InStr(arrScriptMaps(i), "2.0.50727") Then
            arrScriptMaps(i) = Replace(arrScriptMaps(i), "2.0.50727", "1.1.4322")
      End If
Next

objSite.ScriptMaps = arrScriptMaps
objSite.SetInfo

' Change from 1.1 to 2.0

For i = 0 to UBound(arrScriptMaps)
      If InStr(arrScriptMaps(i), "1.1.4322") Then
            arrScriptMaps(i) = Replace(arrScriptMaps(i), "1.1.4322", "2.0.50727")
      End If
Next

objSite.ScriptMaps = arrScriptMaps
objSite.SetInfo

Chris
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris DentPowerShell DeveloperCommented:

Oh and changing the entries in that array does make the change visible in the GUI, so it's nice and accessible afterwards.

Chris
0
Darth_helgeAuthor Commented:
thanks Chris-Dent. I will try this probably on Monday :=)
0
Chris DentPowerShell DeveloperCommented:

Great, let me know how you get on :)

Chris
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft IIS Web Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.