How to use ASP to create Web site functions in IIS _ Application Tips

Source: Internet
Author: User
Tags web services
=============================================================
' Thank you for using the utility function program developed by the ASP001 studio
' HTTP://WWW.ASP001.NET
'=============================================================
' ASP001 Studio to provide you with custom program development, corporate Internet Outreach services
' qq:1974229
' E-mail:shenyangchuqi@tom.com
' More programs download please go to HTTP://WWW.ASP001.NET
'=============================================================
' Function Description: Create website
' This function uses ADSI and requires Administrators group user rights
' Function name: Createwebsite (Computer,ipaddr,portnum,hostname,websitedirectory,logdirectory,websiteinfo,guestusername, Guestuserpass,startorstop)
' Program development: ASP001 Studio Chuqi
' Usage: Createwebsite computer name (a move for localhost or 127.0.0.1), site IP address, port number, host name, site root directory, log file directory site description, site access to use the account number, site access to the password of the account number, Whether to start the site
Example: Createwebsite "LocalHost", "127.0.0.123", "No", "www.test.net", "E:\UserData\UserNum001", "E:\UserData\UserNum001 \logfiles "," wwwtest.net "," iusr_num001_test.net "," abc888 ", True
'=============================================================

Function Createwebsite (computer,ipaddr,portnum,hostname,websitedirectory,logdirectory,websiteinfo,guestusername , Guestuserpass,startorstop)
Dim w3svc, WebServer, Newwebserver, Newdir
Dim bindings, bindingstring, Newbindings, Sitenum, Siteobj, Bdone
On Error Resume Next
Err.Clear
' Detects whether the W3SVC service can be loaded (that is, Web services)
Set w3svc = GetObject ("iis://" & Computer & "/w3svc")
If err.number <> 0 Then ' Show error tips
Response.Write "Cannot open:" & "iis://" & Computer & "/w3svc"
Response.End
End If

' Detects if there is a site with the same IP address, port, and host name
bindingstring = ipaddr & ":" & Portnum & ":" & HostName
For each WebServer in W3SVC
If Webserver.class = "IIsWebServer" Then
Bindings = Webserver.serverbindings
If bindingstring = Bindings (0) Then
Response.Write "IP address conflict:" & ipaddr & ", please detect IP address!."
Exit Function
End If
End If
Next

' Determine a non-existent site number as the new site number, the system default website site number is 1, so starting from 2
sitenum=2
Bdone = False

while (not bdone)
Err.Clear
Set siteobj = GetObject ("iis://" &Computer& "/w3svc/" &sitenum) "loads the specified site
If (err.number = 0) Then
' Response.Write ' step_1 site ' &SiteNum& ' presence '
Sitenum = sitenum + 1
Else
' Response.Write ' step_1 site ' &SiteNum& ' does not exist '
Err.Clear
Set newwebserver = w3svc. Create ("IIsWebServer", Sitenum) ' Creates a specified site
If (err.number <> 0) Then
' Response.Write step_2 site ' &SiteNum& ' Create failed '
Sitenum = sitenum + 1
Else
' Response.Write ' step_2 site &SiteNum& ' Create success '
Bdone = True
End If
End If

If (Sitenum >) Then ' Server maximum number of sites created
Response.Write "exceeds the maximum number of server creation sites, the number of sites being created is:" &SiteNum&. "
Response.End
End If
Wend

' Basic configuration of the site
newbindings = Array (0)
Newbindings (0) = bindingstring
Newwebserver.serverbindings = newbindings
Newwebserver.servercomment= Websiteinfo
Newwebserver.anonymoususername= Guestusername
newwebserver.anonymoususerpass= Guestuserpass
Newwebserver.keytype = "IIsWebServer"
Newwebserver.frontpageweb = True
Newwebserver.enabledefaultdoc = True
Newwebserver.defaultdoc = "default.htm, Default.asp, index.htm, index.asp"
newwebserver.logfiledirectory= logdirectory
Newwebserver.setinfo

Set newdir = newwebserver.create ("IIsWebVirtualDir", "ROOT")
Newdir.path = Websitedirectory
Newdir.accessread = True
Newdir.appfriendlyname = "Application" & Websiteinfo
Newdir.appcreate True
Newdir.accessscript = True
Err.Clear
Newdir.setinfo
If (err.number = 0) Then
Else
Response.Write "The home directory was created with an error."
Response.End
End If

If startorstop = True Then
Err.Clear
Set newwebserver = GetObject ("iis://" & Computer & "/w3svc/" & Sitenum)
Newwebserver.start
If err.number <> 0 Then
Response.Write "Error starting site!"
Response.End
Err.Clear
Else
End If
End If
Response.Write "Site created successfully, the site number is:" & Sitenum & ", the domain name is:" & HostName
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.