Using ASP to create a Web site function in IIS

Source: Internet
Author: User

Program code:

' ========================================================== '
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)
' Usage: Createwebsite computer name (a move for localhost or 127.0.0.1), site IP address, port number, hostname, site root directory, log file directory site description, website access used by the account, the site access to the account used password, Whether to start the site
' Example: Createwebsite "LocalHost", "127.0.0.123", "a", "www.test.net", "e:userdatausernum001",
"E:userdatausernum001logfiles", "cnknow.com", "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 if the W3SVC service (IE Web service) can be loaded
Set w3svc = GetObject ("iis://" & Computer & "/w3svc")
If err.number <> 0 Then ' Show Error hints
Response.Write "Unable to open:" & "iis://" & Computer & "/w3svc"
Response.End
End If
' Detects if there is a site that has the same IP address, port, and host name set
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 check the IP address!."
Exit Function
End If
End If
Next

' Identify a nonexistent 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) ' Load 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& ' not present '
Err.Clear
Set newwebserver = w3svc. Create ("IIsWebServer", Sitenum) ' creates the 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 = "Applications" & Websiteinfo
Newdir.appcreate True
Newdir.accessscript = True
Err.Clear
Newdir.setinfo
If (err.number <> 0) Then
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 launching site!"
Response.End
Err.Clear
End If
End If
Response.Write "Site created successfully, site number is:" & Sitenum & ", the domain name is:" & HostName
End Function


Use ASP settings to specify the maximum CPU usage for a site
Program code:


' =================================================
' Function Description: Set the maximum CPU usage for the specified site
' This function uses ADSI and requires Administrators group user rights
' Function name: Setcpulimitvar (Computer,sitenum,limitvar)
' Usage: Setcpulimitvar computer name, site number, maximum limit value (100=1%,1000=10%)
' Example: Setcpulimitvar ' LocalHost ', ' 2 ', ' 2000 '
' =================================================
Function Setcpulimitvar (Computer,sitenum,limitvar)
Set MyObj001 = GetObject ("iis://" &Computer& "/w3svc/" &sitenum)
' Set Enable CPU throttling
myobj001.cpulimitsenabled = True
' Set limits to use a quota value
Myobj001.cpulimitlogevent=limitvar
Myobj001.setinfo
Set myobj001=nothing
End Function

Use ASP to start/stop a specified Web site

Program code:


' =========================================================
' Function Description: Use ASP to start/stop a specified Web site
' This function uses ADSI and requires Administrators group user rights
' Function name: Adminwebsite (computer,websitenum,dowhat)
' Usage: adminwebsite (computer name, site number, start/stop)
' Example: Start a site with a site number of 1 on a 127.0.0.1 computer
' Adminwebsite ' 127.0.0.1 ', ' 1 ', 1
' Example: Stop a site with a site number of 1 on a 127.0.0.1 computer
' Adminwebsite ' 127.0.0.1 ', ' 1 ', 0
' =======================================================
Function Adminwebsite (Computer,websitenum,dowhat)
On Error Resume Next
Set objserver = GetObject ("iis://" & Computer & "/w3svc/" & Websitenum)
If Err.Number <> 0 Then
Response.Write Now & ". Error code: "& Hex (ERR) &"-"&" Cannot open the specified site <br> "
End If
If Dowhat=1 Then
' Start the site using start
Objserver.start
If Err.Number <> 0 Then
Response.Write "Unable to start the specified Web site <br>"
Else
Response.Write "The specified Web site has been started <br>"
End If
ElseIf Dowhat=0 Then
' Stop the site using stop
Objserver.stop
If Err.Number <> 0 Then
Response.Write "Unable to stop the specified Web site <br>"
Else
Response.Write "The specified Web site has been stopped <br>"
End If
End If
End Function


To list Server Web site information by using ASP

Program code:


' =====================================================
' Function Description: List current server Web site information
' This function uses ADSI and requires Administrators group user rights
' Function name: Listwebsite (computer,num)
' Usage: listwebsite (computer name, display number of sites)
' Example: displaying 1000 site information on a 127.0.0.1 computer
' Listwebsite ', ' 127.0.0.1 ', ' 1000 '
' ====================================================
Function Listwebsite (Computer,num)
On Error Resume Next
Set siteobj = GetObject ("iis://" &Computer& "/w3svc/" &i)
For I=0 to Num
Err.Clear
If Err.number=0 Then
Response.Write "<p><b> Display as computer:" &Computer& All site information </b></p> "
Showwebsite = Siteobj.get ("serverbindings") ' Get site IP address: port: Host Header
Info=split (showwebsite (0), ":")
Response.Write "Site number:" &i& "<br>"
Response.Write "Site IP Address:" &info (0) & "<br>"
Response.Write "Site Port:" &info (1) & "<br>"
Response.Write "Site Host Header:" &info (2) & "<br><br>"
End If
Next
Set siteojb=nothing
End Function

To delete a specified IIS site by using ASP

Program code:


' ======================================================
' Function Description: Delete the specified IIS site
' This function uses ADSI and requires Administrators group user rights
' Function name: Delwebsite (computer,sitenum)
' Usage: Delwebsite computer name, site number
' Example: Delwebsite "127.0.0.1", "2"
' ======================================================
Function Delwebsite (Computer,sitenum)
Set w3svc = GetObject ("iis://" &Computer& "/w3svc")
W3svc.delete "IIsWebServer", Sitenum
Response.Write "deleted successfully! "
End Function


Manage NT accounts with ASP

Program code:


' =======================================================
' Function Description: Manage NT account with ASP
' This function uses ADSI and requires Administrators group user rights
' ====================================================
' Add user
' Function usage: AddUser (computer,username,password,fullname,info)
' Parameters: Computer name, account name, account password, account full name, account description
' Example: AddUser "127.0.0.1", "Test", "tests", "Testing Administrator Account", "This account is filled with ASP"
' Modify basic information for the specified user
' Function usage: edituser (computer,username,oldpassword,password,fullname,info)
' Parameters: Computer name, account name, account password, account full name, account description
' Example: Edituser "127.0.0.1", "Test", "Test2", "Test Administrator account Modification", "This account has been modified through ASP"
' Delete the specified user
' Function usage: deluser (computer,username)
' Parameters: Computer name, user name '
' Example: Deluser ' 127.0.0.1 ', ' Test '
========================================================
Function AddUser (Computer,username,password,fullname,info)
' Execute create account command
Set computerobj = GetObject ("winnt://" &computer)
Set NewUser = computerobj.create ("User", UserName)
Newuser.setinfo
' Make account Settings
Newuser.setpassword (PassWord) ' account password
Newuser.fullname = FullName ' Full name of account
Newuser.description = Info ' account description
Newuser.userflags = &h10000 ' &h20000 (User must change password at next login) &h0040 (user cannot change password) &h10000 (password permanently correct) &h0002 ( Account temporarily deactivated)
Newuser.setinfo
Response.Write "Account" &UserName& "Create success!" "
Set computerobj=nothing
End Function

Function edituser (computer,username,oldpassword,password,fullname,info)
' reads user information
Set changeuserobj = GetObject ("winnt://" &Computer& "/" &UserName& ", User")
' Modify account password
If password<> "then
 changeuserobj.setpassword PassWord
 response.write "account password modified successfully! <br>
End If
modifies the full name of the account
if fullname<> "then
 userfullname = Changeuserobj.get (" FullName "
 changeuserobj.fullname = FullName
 changeuserobj.setinfo
 response.write The full name of the account has been modified successfully! <br> "
End If
" Modify account description
If info<> "then
 userfullname = Changeuserobj.get (" Description ")
 changeuserobj.description = Info
 changeuserobj.setinfo
 response.write "Account description modified successfully! <br>
End If
Set changeuserobj=nothing
End Function

Function Deluser (Computer,username)
Set deluserobj = GetObject ("winnt://" &Computer& "/" &username)
If ERR = &h800401e4 Then
Response.Write "User" &UserName& "not Present"
Response.End
End If
Set DELOBJ = GetObject (deluserobj.parent)
Delobj.delete "User", Deluserobj.name
Set deluserobj = Nothing
Set DELOBJ = Nothing
Response.Write "Delete Succeeded"
End Function


Specifying site resolution scripting language functions using ASP control

Program code:


Function Adminaegis (Computer,sitenum)
Set iiswebserviceobj = GetObject ("iis://" &Computer& "/w3svc/" &sitenum)
Dim Aegis (1)
Aegis (0) = ". Asp,c:winntsystem32inetsrvasp.dll,5,get,head,post,trace"
' Aegis (1) = ". Aspx,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,1,get,head,
Post,debug "
' Parse other files please also use Aegis (num) = "" Format, remember to define the Dim Aegis (num)
'. Htw,c:winntsystem32webhits.dll,3,get,head,post
'. Ida,c:winntsystem32idq.dll,7,get,head,post
'. Idq,c:winntsystem32idq.dll,7,get,head,post
'. Asp,c:winntsystem32inetsrvasp.dll,5,get,head,post,trace
'. Cer,c:winntsystem32inetsrvasp.dll,5,get,head,post,trace
'. Cdx,c:winntsystem32inetsrvasp.dll,5,get,head,post,trace
'. Asa,c:winntsystem32inetsrvasp.dll,5,get,head,post,trace
' .idc,c:winntsystem32inetsrvhttpodbc.dll,5,get,post<br>
'. shtm c:winntsystem32inetsrvssinc.dll,5,get,post<br>
'. sHTML c:winntsystem32inetsrvssinc.dll,5,get,post<br>
'. stm c:winntsystem32inetsrvssinc.dll,5,get,post<br>
'. asax C:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,5,get,head,post,
DEBUG
'. Ascx,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,5,get,head,
Post,debug
'. Ashx,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,1,get,head,
Post,debug
'. Asmx,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,1,get,head,
Post,debug
'. Aspx,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,1,get,head,
Post,debug
'. Axd,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,1,get,head,
Post,debug
'. Vsdisco,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,1,get,head,
Post,debug
'. Rem,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,1,get,head,
Post,debug
'. Soap,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,1,get,head,
Post,debug
'. Config,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,5,get,head,
Post,debug
'. Cs,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,5,get,head,
Post,debug
'. Csproj,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,5,get,head,
Post,debug
'. Vb,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,5,get,head,
Post,debug
'. Vbproj,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,5,get,head,
Post,debug
'. Webinfo,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,5,get,head,
Post,debug
'. Licx,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,5,get,head,
Post,debug
'. Resx,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,5,get,head,
Post,debug
'. Resources,c:winntmicrosoft.netframeworkv1.1.4322aspnet_isapi.dll,5,get,
Head,post,debug
Iiswebserviceobj.scriptmaps=aegis
Iiswebserviceobj.setinfo
' Display Support scripting language
Response.Write "Current site supports parsing list:<br>"
For valueindex = 0 to UBound (iiswebserviceobj.scriptmaps)
Response.Write Iiswebserviceobj.get ("ScriptMaps") (ValueIndex)
Response.Write "<br>"
Next
End Function


Using ASP to list NT user groups and users

Program code:


' =======================================================
' Function Description: Lists NT user groups and users
' This function uses ADSI and requires Administrators group user rights
' Function name: Listgroup (computer)
' Usage: listgroup (computer name)
' Example: Show 127.0.0.1 computer NT user Group and user
' Listgroup ' 127.0.0.1 "
' =======================================================
Function Listgroup (computer)
Response.Write "<p><b> Computer" &Computer& "System user Group and user list </b></p>"
Set computerobj = GetObject ("winnt://" &computer)
Computerobj.filter = Array ("Group")
For each Member in ComputerObj
Response.Write "User group:" &Member.Name& "<br>"
Listuser Computer,member.name
Next
End Function

' List users of the specified user group
Function Listuser (Computer,group)
Set userobj = GetObject ("winnt://" &Computer& "/" &group)
For each Member in Userobj.members
Response.Write "Group Users:" &member.name & "<br>"
Next
End Function

IIS provides IIS Admin Objects, which allows users to administer IIS through a program. IIS Admin Objects is based on Microsoft Active Directory Service Interfaces (ADSI). Any programming language that supports Automation, such as Vbscript/jscript,visual Basic in ASP, Java, or C + +, can use it.
You can modify the address of the IIS default site by referring to the following ASP sample program:
<%
Set IIsObj = GetObject ("Iis://myserver/w3svc/1/root")
IIsObj. Path = "D:newroot"
IIsObj. SetInfo
Set iisobj=nothing
%>
Note: The user must have sufficient permissions to the IIS Metabase.
For information about how to use the program to manage IIS, you can refer to the following articles in MSDN:
Administering IIS Programmatically
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iisref/html/psdk/asp/aint7e9l.asp

Using ASP to create a Web site function in IIS

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.