Using ASP programming to control the establishment of Web sites in IIS

Source: Internet
Author: User
Tags exit ftp site iis port number server port
iis|web| Programming | control | site ' *******************************************************


' Create a webserver


' must be parameter: Wroot, for creating the physical directory of the site; wcomment for site description; Wport for site port; Serverrun for Autorun


' returns 1 when the creation succeeds, prompts to exit when it fails, and returns 0 when the site is successfully created but the startup fails, return 2


''*******************************************************


' **************** Note: Wport is the list type, meaning server port *************


' This function is passed on IIS5.0, * * must be logged on as an administrator * *


' Port example:


' Dim wport,bindlists,createflag,ocomputer


' ocomputer= "LocalHost"


' Binglists=array (0)


' binglists (0) = ": 80:" ' Port number 80


' Wport=binglists


' Createflag=createwebserver ("D:\myweb", "My Home", Wport,false) "Call the Build station function


' If creatflag=0 Then


' Response.Write failed to create the site! Make sure you have permission to "


' ElseIf createflag=1 Then


' Response.Write ' Create site Success! "


' ElseIf createflag=2 Then


' Response.Write Create site successfully, but failed to start site, possible port conflict! "


' ' End If


''********************************************************************************


' about the creation of the FTP site I have published in the ASP version, please have interested friends to see the





Function createwebserver (wroot,wcomment,wport,serverrun)


on Error Resume Next


Dim serviceobj,serverobj,vdirobj


Set serviceobj = GetObject ("iis://" &oComputer& "/w3svc") "Create a service instance first





wnumber=1


Do While IsObject (Serviceobj.getobject ("IIsWebServer", Wnumber))


If err.number<>0 Then


Err.Clear ()


Exit do


End If


wnumber=wnumber+1


Loop





Set serverobj = serviceobj.create ("IIsWebServer", Wnumber) ' then create a Web server





if (err.number <> 0) Then ' ERROR


' Response.Write Error: ADSI operation failed to create Web server! "


createwebserver=0


Exit Function


End If





' then configure the server


serverobj.serversize = 1 ' Medium size


serverobj.servercomment = wcomment ' Description


serverobj.serverbindings = Wport ' Port


serverobj.enabledefaultdoc=true





' Submit information


Serverobj.setinfo





' Finally, set up a virtual directory


Set vdirobj = serverobj.create ("IIsWebVirtualDir", "ROOT")





if (err.number <> 0) Then ' ERROR


' Response.Write Error: ADSI operation to create virtual directory failed! "


createwebserver=0


Exit Function


End If





' Configure the virtual directory


Vdirobj.path = Wroot


Vdirobj.accessread = True


vdirobj.accesswrite = True


vdirobj.enabledirbrowsing = False


Vdirobj.enabledefaultdoc=true


vdirobj.accessscript=true


Vdirobj.appcreate2 2


vdirobj.appfriendlyname= "Default Application"


Vdirobj.setinfo





If serverrun = True Then


Serverobj.start


If (err.number <> 0) Then ' error!


' Response.Write Error: An error occurred while starting the server! Please start webserver "&WComment&" Manually! <br> "


createwebserver=2


Exit Function


End If


End If


Set vdirobj=nothing


Set serverobj=nothing


Set serviceobj=nothing


createwebserver=1


End Function











Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.