I'm trying to automate creating a website in IIS using classic asp.
I've used the solution in this thread http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Microsoft_IIS/Q_21031974.html
but have become stuck with the settings I need for the security as all I'm getting is permission denied messages. I did have it working but now it's stopped and not sure why.
I have the following situation:
Windows2003 server running IIS6
I have a main admin user lets say called Admin :)
I have a domain group called DomainGroup :)
I have the usual IUSR account as well...DomainGroup is just a domain group that will hold all my created domains....hopefully.
DomainGroup is the owner of domain1 and domain2
domain1 contains code that happily creates the folder structure for domain3 within the DomainGroup folder by copying everything from domain2 (my template site)
That bit works ok...now trying to do the IIS bit -
Firstly, this line
set websrv = getobject("IIS://DSVR00945
6/W3SVC") no longer works and returns a permssion denied error.
This is where I get stuck as I'm not sure what account needs what anymore and I'm losing the will to live!
What is actually running the script....IUSR or domainGroup?
What settings do I change and where? Please go through step by step as I'm really really confused now!
Attached my code below
newSite = "example.com"
dim websrv, site
set websrv = getobject("IIS://DSVR009456/W3SVC")
if (err <> 0) then
for each site in websrv
if instr(Site.ServerComment,newSite) > 0 then
if err.number = 0 then
on error goto 0
if not exists then
' first of all copy the blank site
set fso = createobject("scripting.filesystemobject")
if fso.folderExists("d:\home\domainGroup\" & newSite) then
' don't create folders - they already exist
fso.createFolder("d:\home\domainGroup\" & newSite)
fso.CopyFolder "d:\home\domainGroup\domain1\*", "d:\home\domainGroup\" & newSite
response.Write("<p>" & newSite & " directories created</p>")
' Make connections to WMI, to the IIS namespace on MyMachine, and to the Web service.
set locatorObj = CreateObject("WbemScripting.SWbemLocator")
set providerObj = locatorObj.ConnectServer("DSVR009456", "root/MicrosoftIISv2")
set serviceObj = providerObj.Get("IIsWebService='W3SVC'")
' Build binding object, which is a required parameter of the CreateNewSite method.
' Use the SpawnInstance WMI method since we are creating a new instance of an object.
Bindings = Array(0)
Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_()
Bindings(0).IP = ""
Bindings(0).Port = "80"
Bindings(0).Hostname = newSite
' Create the new Web site using the CreateNewSite method of the IIsWebService object.
strSiteObjPath = serviceObj.CreateNewSite(newSite, Bindings, "D:\home\domainGroup\" & newSite & "\htdocs")
If Err Then
response.Write( "*** Error Creating Site: " & Hex(Err.Number) & ": " & Err.Description & " ***")
' strSiteObjPath is in the format of IIsWebServer='W3SVC/1180970907'
' To parse out the absolute path, W3SVC/1180970907, use the SWbemObjectPath WMI object.
Set objPath = CreateObject("WbemScripting.SWbemObjectPath")
objPath.Path = strSiteObjPath
strSitePath = objPath.Keys.Item("")
' Set some properties on the root virtual directory which was created by CreateNewSite.
Set vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" & strSitePath & "/ROOT'")
vdirObj.AuthFlags = 5 ' AuthNTLM + AuthAnonymous
vdirObj.EnableDefaultDoc = True
vdirObj.DirBrowseFlags = &H4000003E ' date, time, size, extension, longdate
vdirObj.AccessFlags = 513 ' read, script
vdirObj.AppFriendlyName = ""
' Save the new settings to the metabase
' CreateNewSite does not start the server, so start it now.
Set serverObj = providerObj.Get(strSiteObjPath)
response.Write("The site already existed")