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

Source: Internet
Author: User
Tags ftp site


"' *******************************************************
"Create a webserver
"Required Parameters: Wroot, to create the physical directory of the site; wcomment for the site description; Wport is the site port; Serverrun to run automatically
"" returns 1 when creation succeeds, prompts to exit when failed and returns 0, returns 2 when the site is created successfully but fails to start
"' *******************************************************
"**************** Note: Wport is a list type, meaning server port *************
' This function is passed on IIS5.0, * * must be logged in as an administrator * *
"Port Example:
"Dim Wport,bindlists,createflag,ocomputer
" ocomputer=" LocalHost "
"Binglists=array (0)
" binglists (0) =": 80: "" The port number is
"' Wport=binglists
" createflag=createwebserver (" D:\myweb "," My Homeland ", Wport,false)" Call the Build station function
"If creatflag=0 Then
' Response.Write ' failed to create the site! Please determine if you have permission "
"' ElseIf createflag=1 Then
"Response.Write" created the site successfully! " 
"' ElseIf createflag=2 Then
' Response.Write ' created the site successfully, but failed to start the site, possibly Port conflict! " 
' End If
"' ********************************************************************************
"about the creation of the FTP site I have published in the ASP version, please have interested friends to see for themselves

Function Createwebserver (Wroot,wcomment,wport,serverrun)
On Error Resume Next
Dim Serviceobj,serverobj,vdirobj
Set serviceobj = GetObject ("iis://" &oComputer& "/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) "and then create a Web server

if (err.number <> 0) then "error
' Response.Write ' ERROR: The ADSI operation to create the Web server failed! "
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", "ROOT")

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

' Configure Virtual directories
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> "&NBSP;
createwebserver=2 
Exit function 
End if 
End if 
Set vdirobj =nothing 
set serverobj=nothing 
set serviceobj=nothing 
createwebserver=1 
End Function

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.