_asp the basics of using ASP to create Web site functions in IIS

Source: Internet
Author: User
Tags cpu usage

Program code:

'=========================================================='
Introduction to Functions: Creating 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, 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: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 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
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
End If
End If
Response.Write "Site created successfully, the site number is:" & Sitenum & ", the domain name is:" & HostName
End Function


Use ASP settings to specify site CPU maximum usage
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 (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 limit values
Myobj001.cpulimitlogevent=limitvar
Myobj001.setinfo
Set myobj001=nothing
End Function

Start/stop specifying a Web site using ASP

Program code:


'=========================================================
' Function Description: Use ASP to start/stop the 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 the 127.0.0.1 computer
' Adminwebsite ' 127.0.0.1 ', ' 1 ', 1
' Example: Stop 127.0.0.1 a site with a site number of 1 on the 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) &"-"&" could not open the specified site <br> "
End If
If Dowhat=1 Then
' Start the site with start
Objserver.start
If err.number <> 0 Then
Response.Write "Cannot start the specified Web site <br>"
Else
Response.Write "has started the specified Web site <br>"
End If
ElseIf Dowhat=0 Then
' Stop site with stop
Objserver.stop
If err.number <> 0 Then
Response.Write "Cannot stop specifying Web site <br>"
Else
Response.Write "has stopped specifying Web sites <br>"
End If
End If
End Function


Using ASP to List Server Web site information

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, show number of sites)
' Example: Display 1000 site information on 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> The following appears as computer:" &Computer& "All site information </b></p>"
Showwebsite = Siteobj.get ("serverbindings") ' Get site IP address: port: main 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 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 "Delete Success!" "
End Function


Managing NT accounts through ASP

Program code:


'=======================================================
' Function Description: Manage NT account through ASP
' This function uses ADSI and requires Administrators group user rights
'====================================================
' Fill in the user
' Functional 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 number through ASP add"
' Modify the specified user profile
' Functional 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
' Functional 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 ' account name
Newuser.description = Info ' account description
Newuser.userflags = &h10000 ' &h20000 (User must change password at next login) &h0040 (user must not change password) &h10000 (password permanently correct) &h0002 ( Account temporarily inactive)
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 modification success!" <br> "
End If
" Modify account name
if fullname<> "" then
 userfullname = Changeuserobj.get ("FullName"
 changeuserobj.fullname = FullName
 changeuserobj.setinfo
 response.write account full name modified successfully! <br> "
End If
" Modify account description
If info<> "" then
 userfullname = Changeuserobj.get ("Description")
 changeuserobj.description = Info
 changeuserobj.setinfo
 response.write "account changes succeeded!" <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& "does not exist"
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


Using ASP to control the specified site resolution script language function

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 "
' Resolve other files please use the same format as Aegis = ', remember to define 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
' Show support scripting language
Response.Write "Current site support Resolution list:<br>"
For valueindex = 0 to UBound (iiswebserviceobj.scriptmaps)
Response.Write Iiswebserviceobj.get ("ScriptMaps") (ValueIndex)
Response.Write "<br>"
Next
End Function


Use ASP to list NT user groups and users

Program code:


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

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

IIS provides IIS Admin Objects, allowing 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, Java, or C + + in ASP, can be used.
You can refer to the following ASP sample program to modify the address of the IIS default site:
<%
Set IIsObj = GetObject ("Iis://myserver/w3svc/1/root")
IIsObj. Path = "D:newroot"
IIsObj. SetInfo
Set iisobj=nothing
%>
Note: The user must have sufficient permissions on the IIS Metabase.
For information on how to manage IIS using a program, 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
Read the full text (55) | Reply (0) | Trackbacks (0) | Edit

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.