ASP controls the virtual host function ADSI

Source: Internet
Author: User
Use ASP to set the maximum CPU usage of a specified site
'================================================ ============
'Function Introduction: sets the maximum CPU usage of a specified site.
'This function uses ADSI and requires the permissions of the Administrators group.
'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 CPU limit Enabled
Myobj001.cpulimitsenabled = true
'Set the limit value
Myobj001.cpulimitlogevent = limitvar
Myobj001.setinfo
Set myobj001 = nothing
End Function

Functions used to create a web site in IIS using ASP
'================================================ ======================================
'Function Introduction: create a website
'This function uses ADSI and requires the permissions of the Administrators group.
'Function name: createwebsite (computer, ipaddr, portnum, hostname, websitedirectory, logdirectory, websiteinfo, guestusername, guestuserpass, startorstop)
'Usage: createwebsite computer name (localhost or 127.0.0.1), site IP address, port number, host name, site root directory, and site description of log file directory, the account used for Website access, the password of the account used for Website access, and whether to start the website
'Example: createwebsite "localhost", "127.0.0.123", "80", "www.test.net", "E:/userdata/usernum001", "E:/userdata/usernum001/logfiles ", "wwwtest.net", "iusr_num0020.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
'Check whether the w3svc Service (Web Service) can be loaded)
Set w3svc = GetObject ("IIS: //" & Computer & "/W3SVC ")
If err. Number <> 0 then': an error message is displayed.
Response. Write "cannot be enabled:" & "IIS: //" & Computer & "/W3SVC"
Response. End
End if
'Check whether a site with the same IP address, port, and host name has been 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

'Determine a site number that does not exist as the new site number. The default website site number is 1, so it starts 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 & ""
Sitenum = sitenum + 1
Else
'Response. Write "step_1 site" & sitenum & "nonexistent"
Err. Clear
Set newwebserver = W3SVC. Create ("iiswebserver", sitenum) 'create a specified site
If (ERR. Number <> 0) then
'Response. Write "step_2 site" & sitenum & "creation failed"
Sitenum = sitenum + 1
Else
'Response. Write "step_2 site" & sitenum & "created successfully"
Bdone = true
End if
End if
If (sitenum> 50) then' the maximum number of site creation points on the server
Response. Write "exceeds the maximum number of site creation points on the server. The number of the site being created is:" & sitenum &"."
Response. End
End if
Wend

'Perform basic site configuration
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. enabledefadoc Doc = 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 "An error occurred while creating the main directory ."
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 "An error occurred while starting the site! "
Response. End
Err. Clear
End if
End if
Response. Write "site created successfully. Site No.:" & sitenum & ", domain name:" & hostname
End Function

Use ASP to start/stop a specified web site
'================================================ ======================================
'Function Introduction: use ASP to start/stop a specified web site
'This function uses ADSI and requires the permissions of the Administrators group.
'Function name: adminwebsite (computer, websitenum, dowhat)
'Usage: adminwebsite (computer name, site number, start/stop)
'Example: Start a site numbered 1 on 127.0.0.1
'Adminwebsite "127.0.0.1", "1", 1
'For example, stop a site numbered 1 on 127.0.0.1
'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) & "-" & "the specified site cannot be started <br>"
End if
If dowhat = 1 then
'Start the site
Objserver. Start
If err. Number <> 0 then
Response. write "the specified web site cannot be started <br>"
Else
Response. write "the specified web site has been started <br>"
End if
Elseif dowhat = 0 then
'Stop the site with stop'
Objserver. Stop
If err. Number <> 0 then
Response. write "the specified web site cannot be stopped <br>"
Else
Response. write "the specified web site has been stopped <br>"
End if
End if
End Function

Use ASP to list server web site information
'================================================ ======================================
'Function Introduction: lists the current server web site information
'This function uses ADSI and requires the permissions of the Administrators group.
'Function name: listwebsite (computer, num)
'Usage: listwebsite (computer name, display site count)
'Example: displays information about 1000 websites on 127.0.0.1 computers.
'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 shows the computer:" & Computer & "All Site Information </B> </P>"
Showwebsite = siteobj. Get ("serverbindings") 'obtain the site IP Address: Port: Host Header
Info = Split (showwebsite (0 ),":")
Response. Write "Site No.:" & 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>"
End if
Next
Set siteojb = nothing
End Function

Use ASP to delete a specified IIS Site
'================================================ ======================================
'Function Introduction: delete a specified IIS Site
'This function uses ADSI and requires the permissions of the Administrators group.
'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 through ASP
'================================================ ======================================
'Function Introduction: Managing nt accounts through ASP
'This function uses ADSI and requires the permissions of the Administrators group.
'================================================ ======================================
'Add user
'Function usage: adduser (computer, username, password, fullname, Info)
'Parameter: computer name, account name, account password, account full name, account description
'Example: adduser "127.0.0.1", "test administrator account", "add this account through ASP"
'Modify basic user information
'Function usage: edituser (computer, username, oldpassword, password, fullname, Info)
'Parameter: 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 a specified user
'Function usage: deluser (computer, username)
'Parameter: computer name, username'
'Example: deluser "127.0.0.1", "test"
========================================================== ==================================
Function adduser (computer, username, password, fullname, Info)
'Execute the Account creation command
Set computerobj = GetObject ("winnt: //" & Computer)
Set newuser = computerobj. Create ("user", username)
Newuser. setinfo
'Set the account
Newuser. setpassword (password) 'account password
Newuser. fullname = fullname 'account full name
Newuser. Description = info' account description
Newuser. userflags = & h10000' & h20000 (the user must change the password upon next login) & h0040 (the user cannot change the password) & h10000 (the password is correct permanently) & h0002 (the account is temporarily disabled)
Newuser. setinfo
Response. Write "Account" & username & "created successfully! "
Set computerobj = nothing
End Function

Function edituser (computer, username, oldpassword, password, fullname, Info)
'Read user information
Set changeuserobj = GetObject ("winnt: //" & Computer & "/" & username & ", user ")
'Change the account password
If password <> "" then
Changeuserobj. setpassword Password
Response. Write "account password changed! <Br>"
End if
'Modify account full name
If fullname <> "then
Userfullname = changeuserobj. Get ("fullname ")
Changeuserobj. fullname = fullname
Changeuserobj. setinfo
Response. write "the full name of the account has been modified! <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 & "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 "deleted successfully"
End Function

Use ASP to control the parsing script language functions of specified sites
Function adminaegis (computer, sitenum)
Set iiswebserviceobj = GetObject ("IIS: //" & Computer & "/w3svc/" & sitenum)
Dim Aegis (1)
Aegis (0) = ". asp, C:/winnt/system32/inetsrv/asp. dll, 5, get, Head, post, trace"
'Aegis (1) = ". aspx, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 1, get, Head, post, debug"
'Use the same format as Aegis (Num) = "" to parse other files. Remember to define dim Aegis (Num ).
'. HTW, C:/winnt/system32/webhits. dll, 3, get, Head, post
'. Ida, C:/winnt/system32/idq. dll, 7, get, Head, post
'. Idq, C:/winnt/system32/idq. dll, 7, get, Head, post
'. Asp, C:/winnt/system32/inetsrv/asp. dll, 5, get, Head, post, trace
'. CER, C:/winnt/system32/inetsrv/asp. dll, 5, get, Head, post, trace
'. CDX, C:/winnt/system32/inetsrv/asp. dll, 5, get, Head, post, trace
'. Asa, C:/winnt/system32/inetsrv/asp. dll, 5, get, Head, post, trace
'. IDC, C:/winnt/system32/inetsrv/httpodbc. dll, 5, get, post <br>
'. Shtm C:/winnt/system32/inetsrv/ssinc. dll, 5, get, post <br>
'.Shtml C:/winnt/system32/inetsrv/ssinc. dll, 5, get, post <br>
'. Stm C:/winnt/system32/inetsrv/ssinc. dll, 5, get, post <br>
'. Asax C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 5, get, Head, post, debug
'. Ascx, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 5, get, Head, post, debug
'. Ashx, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 1, get, Head, post, debug
'. Asmx, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 1, get, Head, post, debug
'. Aspx, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 1, get, Head, post, debug
'. Axd, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 1, get, Head, post, debug
'. Vsdisco, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 1, get, Head, post, debug
'. REM, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 1, get, Head, post, debug
'. Soap, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 1, get, Head, post, debug
'. Config, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 5, get, Head, post, debug
'. CS, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 5, get, Head, post, debug
'. Csproj, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 5, get, Head, post, debug
'. VB, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 5, get, Head, post, debug
'. Vbproj, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 5, get, Head, post, debug
'. Webinfo, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 5, get, Head, post, debug
'. Licx, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 5, get, Head, post, debug
'. Resx, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 5, get, Head, post, debug
'. Resources, C:/winnt/Microsoft. NET/framework/v1.1.4322/aspnet_isapi.dll, 5, get, Head, post, debug
Iiswebserviceobj. scriptmaps = Aegis
Iiswebserviceobj. setinfo
'Show supported scripting languages
Response. Write "Resolution list supported by current site: <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

'================================================ ======================================
'Function Introduction: List NT user groups and users
'This function uses ADSI and requires the permissions of the Administrators group.
'Function name: listgroup (Computer)
'Usage: listgroup (computer name)
'Example: displays the NT user group and user of 127.0.0.1 computer.
'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 each member in computerobj
Response. Write "User Group:" & member. Name & "<br>"
Listuser computer, member. Name
Next
End Function

'List users of a specified user group
Function listuser (computer, Group)
Set userobj = GetObject ("winnt: //" & Computer & "/" & Group)
For each member in userobj. Members
Response. Write "& nbsp; group users:" & member. Name & "<br>"
Next
End Function

From: http://goaler.xicp.net/ShowLog.asp? Id = 479

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.