Using ASP programming to control the program code that establishes the Web site in IIS

Source: Internet
Author: User
Tags exit ftp site iis port number server port

'*****************************************************
' Create a webserver
' must parameter: Wroot, to create the physical directory of the site; wcomment for site description; Wport for site port; Serverrun to run automatically
' Returns 1 when the creation succeeds, prompts to exit when it fails, and returns 0 when the site is successfully created but failed to start. 2
'******************************************************
'
' ****************** Note: Wport is a 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 is 80
' Wport=binglists
' Createflag=createwebserver ("" "" D:\myweb "" "", "" "" "" "," "" "," ", Wport,false)" Call the Build station function
' If creatflag=0 Then
' Response.Write ' "" Create Site failed! Make sure you have permission "" "" "
' ElseIf createflag=1 Then
' Response.Write ' "" Create site Success! """"
' ElseIf createflag=2 Then
' Response.Write ' "" "Create site success, but failed to start site, possible port conflicts! """"
' End If
'*********************************************************
' About the creation of the FTP site I have published in the ASP version, please have interested friends to see for themselves
' If you have any questions, please feel free to contact me: nonepassby@163.com

Function Createwebserver (Wroot,wcomment,wport,serverrun)
On Error Resume Next
Dim Serviceobj,serverobj,vdirobj
Set serviceobj = GetObject ("" "iis://" "" "" "" "" "" "", ""/w3svc "" ") ' first create a service instance

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, create a virtual directory
Set vdirobj = serverobj.create ("" "IIsWebVirtualDir" "" "," ""

if (err.number <> 0) Then ' ERROR
' Response.Write ' "" Error: ADSI operation failed to create virtual directory! """"
Createwebserver=0
Exit Function
End If

  Configure virtual directories  
  Vdirobj.path = wroot 
  Vdirobj.accessread = true 
  Vdiro bj. AccessWrite = true 
  vdirobj.enabledirbrowsing = false 
  vdirobj.enabledefaultdoc=true& nbsp
  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: Error starting server! Please manually start webserver "" "" &WComment& "" ""! <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.