Program code:
'================================================ ============================='
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: userdatausernum001 ",
"E: userdatausernum001logfiles", "cnknow. com", "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 set the maximum CPU usage of a specified site
Program code:
'================================================ ============
'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
Use ASP to start/stop a specified web site
Program code:
'================================================ ============================
'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
Program code:
'================================================ ====================
'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
Program code:
'================================================ ====================
'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
Program code:
'================================================ ======================
'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
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"
'Use the same format as Aegis (Num) = "" to parse other files. 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 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
Program code:
'================================================ ======================
'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
IIS provides IIS admin objects, allowing you to manage IIS through programs. 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 use it.
You can refer to the following ASP Sample program to modify the address of the default IIS Site:
<%
Set iisobj = GetObject ("IIS: // myserver/w3svc/1/root ")
Iisobj. Path = "D: newroot"
Iisobj. setinfo
Set iisobj = nothing
%>
Note: You must have sufficient permissions for IIS metabase.
For how to use programs to manage IIS, refer to the following articles on msdn:
Administering IIS programmatically
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/iisref/html/psdk/asp/aint7e9l. asp