Use ASP programming to control the creation of web sites in IIS)

Source: Internet
Author: User
Tags ftp site
Use ASP programming to control the creation of web sites in IIS

''************************************** *****************
''Create a webserver
''Required parameter: wroot, which is the physical directory of the site to be created; wcomment is the site description; wport is the site port; serverrun is the automatic operation
''1 is returned when the site is successfully created, 0 is returned when the site fails to be created, and 2 is returned when the site is successfully created but fails to be started.
''************************************** *****************
''****************** Note: wport is of the list type, indicates the server port *************
''This function is used on iis5.0. ** you must log on as an administrator **
''Port example:
''Dim wport, bindlists, createflag, ocomputer
''Ocomputer = "localhost"
''Binglists = array (0)
''Binglists (0) = ": 80:" ''port: 80
''Wport = binglists
''Createflag = createwebserver ("D:/myweb", "my home", wport, false )''
''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
''************************************** **************************************** **
''About FTP site creation I have published it in ASP. Please check it by yourself if you are interested.

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'' is an error?
''Response. Write "error: An error occurred while creating the ADSI operation for the 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. enabledefadoc Doc = true

''Submit information
Serverobj. setinfo

''Finally, create a virtual directory
Set vdirobj = serverobj. Create ("iiswebvirtualdir", "root ")

If (ERR. Number <> 0) then'' is an 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

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.