Solved

trying to create website programmitically in IIS 6

Posted on 2009-07-13
5
301 Views
Last Modified: 2012-05-07
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://DSVR009456/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

dim webinfo,exists

exists=false

set websrv = getobject("IIS://DSVR009456/W3SVC")

if (err <> 0) then

else

    err.Clear

    for each site in websrv

	if instr(Site.ServerComment,newSite) > 0 then

	if err.number = 0 then 

		exists=true 

	else

		err.clear

	end if

	end if

    next

end if

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

	else

	  fso.createFolder("d:\home\domainGroup\" & newSite)

	  fso.CopyFolder "d:\home\domainGroup\domain1\*", "d:\home\domainGroup\" & newSite

	end if

	

	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.

	Dim strSiteObjPath

	strSiteObjPath = serviceObj.CreateNewSite(newSite, Bindings, "D:\home\domainGroup\" & newSite & "\htdocs")

	If Err Then

	response.Write( "*** Error Creating Site: " & Hex(Err.Number) & ": " & Err.Description & " ***")

	response.End()

	End If

	

	' 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

	vdirObj.Put_()

	

	' CreateNewSite does not start the server, so start it now.

	Set serverObj = providerObj.Get(strSiteObjPath)

	serverObj.Start

	

	response.Write(strSitePath)

else

	response.Write("The site  already existed")
 

end if

Open in new window

0
Comment
Question by:webbysteve
  • 3
5 Comments
 
LVL 7

Expert Comment

by:wrwilson
ID: 24838982
Can you post the error messages?
0
 

Author Comment

by:webbysteve
ID: 24839056
Hi wrwilson.

The only error messages are "permission denied" ones. However as an update to this, I've (literally) just managed - i think - to get it working again by restarting the server after making IUSR a member of the administrators group. Probably not a good idea but it works...unless someone tells me that is ok?

However this has thrown up another problem as I thought the system created DNS entries too but doesn't seem to. I may need to raise that as another question although it's linked to this - if anyone has tried to automate creating websites then I'm sure they've need to create DNS records too. I've tried to create files in the servers/dns/ folder but they don't seem to be recognised.

groping in the dark so any help appreciated.

0
 

Author Comment

by:webbysteve
ID: 24842403
Sorry chaps - think I've sorted myself but this might prove useful for others.....

Because all my created sites will be subdomains all I had to do was add an A record of *. That's it. Every subdomain site I create now will automatically work. No trying to use WMI, ADSI or anything else locally or remotely to configure the DNS....so far so good it's still working after a reboot.

The IIS bit was just permissions too, not sure if it's right or secure but I'll carry on looking with that.
0
 

Accepted Solution

by:
webbysteve earned 0 total points
ID: 24950899
Actually - scrap all I said above, I've found a windows server component that lets you log on as admin during an asp page, plus run command line instructions to create IIS websites in a windowless environment then log out. All on the same page. www.zbitinc.com

elegant, secure, no server permissions to hack around. bliss. How much? $19. less than the membership to this website!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now