<%
'*************************************** **************************************** ***
'Create a webserver
'Required parameter: wroot, which is the physical directory of the site to be created; wcomment indicates the site description; wport indicates the site port; serverrun indicates whether the site runs automatically
'If the site is successfully created, 1 is returned. If the site fails to be created, 0 is returned. if the site is successfully created but the start fails, 2 is returned.
'*************************************** **************************************** ***
'
'****************** Note: wport is of the list type, indicating the server port, ***************
'The function passed on iis5.0. ** you must log on as an administrator **
'Example of Port:
'Dim wport, bindlists, createflag, ocomputer
'Ocomputer = "localhost"
'Binglists = array (0)
'Binglists (0) = ": 80:" 'the port number is 80.
'Wport = binglists
'Createflag = createwebserver ("D: myweb", "my home", wport, false) 'calls the website creation Function
'If creatflag = 0 then
'Response. Write "An error occurred while creating the site! Please confirm whether you have the permission"
'Elseif createflag = 1 then
'Response. Write "site created successfully! "
'Elseif createflag = 2 then
'Response. write' the site is successfully created, but the site fails to be started. A port conflict may occur! "
'End if
'*************************************** **************************************** *
'The creation of an FTP site has been published in ASP. Please check it out by yourself.
'If you have any questions, please contact me: nonepassby@163.com
Function createwebserver (wroot, wcomment, wport, serverrun)
On Error resume next
Dim serviceobj, serverobj, vdirobj
Set serviceobj = GetObject ("IIS: //" & ocomputer & "/W3SVC") 'first creates 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: An error occurred while creating the ADSI operation on the Web server! "
Createwebserver = 0
Exit Function
End if
'Configure the server
Serverobj. serversize = 1' Medium Size
Serverobj. servercomment = wcomment 'description
Serverobj. serverbindings = wport' Port
Serverobj. enabledefadoc Doc = 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: An error occurred while creating the ADSI operation for the virtual directory! "
Createwebserver = 0
Exit Function
End if
'Configure the virtual directory
Vdirobj. Path = wroot
Vdirobj. accessread = true
Vdirobj. accesswrite = true
Vdirobj. enabledirbrowsing = false
Vdirobj. enabledefadoc Doc = 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! Start webserver manually "& wcomment &"! <Br>"
Createwebserver = 2
Exit Function
End if
End if
Set vdirobj = nothing
Set serverobj = nothing
Set serviceobj = nothing
Createwebserver = 1
End Function
%>