SoFunction
Updated on 2025-03-09

Functions to create WEB site in IIS using ASP

Program code:

'=========================================================='
Function introduction: Creating WebSite
'This function uses ADSI and requires Administrators group user permissions
'Function name: CreateWebSite(Computer, IPAddr, PortNum, HostName, WebSiteDirectory, LogDirectory, WebSiteInfo,
GuestUserName,GuestUserPass,StartOrStop)
'Usage: CreateWebSite computer name (first to LocalHost or 127.0.0.1), site IP address, port number, host name, site root directory, LOG file directory site description, account used when accessing the website, password of the account used when accessing the website, whether to start the site
'Example: CreateWebSite "LocalHost","127.0.0.123","80","","E:UserDataUserNum001",
"E:UserDataUserNum001LogFiles","","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

'Check whether the W3SVC service can be loaded (i.e. WEB service)
Set w3svc = GetObject("IIS://" & Computer & "/w3svc")
If <> 0 Then 'Show error message
"Cannot open: "&"IIS://" & Computer & "/w3svc"
 
End If
'Detect whether there is a site with the same IP address, port and host name
BindingString = IPAddr & ":" & PortNum & ":" & HostName
For Each WebServer in w3svc
 If = "IIsWebServer" Then
 Bindings =
 If BindingString = Bindings(0) Then
"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 system defaults to WebSite site number is 1, so start from 2
SiteNum=2
bDone = False
While (Not bDone)

Set SiteObj = GetObject("IIS://"&Computer&"/w3svc/"&SiteNum) 'Load the specified site
If ( = 0) Then
' " Step_1 Site"&SiteNum&"existence"
 SiteNum = SiteNum + 1
Else
' " Step_1 Site"&SiteNum&"Don't exist"
 
Set NewWebServer = ("IIsWebServer",SiteNum) 'Create a specified site
 If ( <> 0) Then
' "Step_2 site"&SiteNum&"Creation failed"
 SiteNum = SiteNum + 1
 Else
' " Step_2 Site"&SiteNum&"created successfully"
 bDone = True
 End If
End If
If (SiteNum > 50) Then 'The maximum number of sites created by the server
"The maximum number of sites created by the server exceeds the server, the serial number of the site being created is: "&SiteNum&"."
 
End If
Wend

'Carring basic site configuration
NewBindings = Array(0)
NewBindings(0) = BindingString
= NewBindings
= WebSiteInfo
= GuestUserName
= GuestUserPass
= "IIsWebServer"
= True
= True
= ", , , "
= LogDirectory

Set NewDir = ("IIsWebVirtualDir", "ROOT")
= WebSiteDirectory
= true
= "Application" & WebSiteInfo
True
= True


If ( <> 0) Then
"An error occurred while creating the home directory."
 
End If
If StartOrStop = True Then
 
 Set NewWebServer = GetObject("IIS://" & Computer & "/w3svc/" & SiteNum)
 
 If <> 0 Then
"An error occurred while starting the site!"
 
 
 End If
End If
"Site created successfully, the site number is: "& SiteNum &" and the domain name is: "& HostName
End Function


Use ASP to set the maximum usage of the site CPU.
Program code:


'=================================================
'Function introduction: Set the maximum usage level of CPU at the specified site
'This function uses ADSI and requires Administrators group user permissions
'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 limits
= True
'Set limit usage limit value
=LimitVar

Set MyObj001=Nothing
End Function

Start/stop specifying WEB site using ASP

Program code:


'=========================================================
'Function introduction: Start/stop specifying WEB site using ASP
'This function uses ADSI and requires Administrators group user permissions
'Function name: AdminWebSite(Computer,WebSiteNum,DoWhat)
'Usage: AdminWebSite (computer name, site number, start/stop)
'Example: Start a site with site number 1 on the 127.0.0.1 computer
'AdminWebSite "127.0.0.1","1",1
'Example: Stop the site with site number 1 on the 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 <> 0 Then
Now & ". Error code: " & Hex(Err)& " - " & "Cannot open the specified site<br>"
End If
if Dowhat=1 then
'Use Start the site
 
 If <> 0 Then
"Cannot start the specified web site<br>"
 else
"The specified web site has been started<br>"
 End If
elseif DoWhat=0 then
'Stop the site using Stop
 
 If <> 0 Then
"Cannot stop specifying a Web site<br>"
 else
"Specifying Web Sites has been stopped<br>"
 End If
end if
End Function


Use ASP to list server WEB site information

Program code:


'=====================================================
'Function introduction: List the current server WEB site information
'This function uses ADSI and requires Administrators group user permissions
'Function name: ListWebSite (Computer,Num)
'Usage: ListWebSite (computer name, display number of sites)
'Example: Display 1000 site information 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
 
 if =0 then
"<p><b>The following is shown as computer: "&Computer&"All site information</b></p>"
ShowWebSite = ("ServerBindings") 'Get site IP address: Port: Host header
 Info=split(ShowWebSite(0),":")
"Site number: "&i&"<br>"
"Site IP address: "&Info(0)&"<br>"
"Site Port:"&Info(1)&"<br>"
"Site Host Header:"&Info(2)&"<br><br>"
 end if
next
set SiteOjb=nothing
End Function

Use ASP to delete a specified IIS site

Program code:


'======================================================
'Function Introduction: Delete the specified IIS site
'This function uses ADSI and requires Administrators group user permissions
'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")
"IIsWebServer",SiteNum
"Delete successfully!"
End Function


Manage NT accounts through ASP

Program code:


'=======================================================
'Function introduction: Manage NT accounts through ASP
'This function uses ADSI and requires Administrators group user permissions
'====================================================
'Fill in with the 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","Test","Test","Test Administrator Account", "This account is filled in through ASP"
'Modify the basic information of 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 the Create Account command
Set ComputerObj = GetObject("WinNT://"&Computer)
Set NewUser = ( "User" , UserName )

'Make account settings
( PassWord ) 'Account Password
= FullName 'Account full name
= Info 'Account Description
= &H10000 '&H20000 (the user must change his password next time he logs in) &H0040 (the user may not change his password) &H10000 (the password is permanently correct) &H0002 (the account is temporarily disabled)

"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")
'Modify account password
if PassWord<>"" then
  PassWord
"Account password modified successfully!<br>"
end if
'Modify the full name of the account
if FullName<>"" then
 UserFullName = ("FullName")
  = FullName
 
"The full name of the account was modified successfully!<br>"
end if
'Modify account instructions
if Info<>"" then
 UserFullName = ("Description")
  = Info
 
"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
"User"&UserName&"Don't exist"
 
End If
Set DelObj = GetObject()
"User",
Set DelUserObj = Nothing
Set DelObj = Nothing
"Delete successfully"
End Function


Use ASP to control the specified site parsing script language function

Program code:


Function AdminAegis(Computer,SiteNum)
Set IIsWebServiceObj = GetObject("IIS://"&Computer&"/W3SVC/"&SiteNum)
dim Aegis(1)
Aegis(0)=".asp,C:,5,GET,HEAD,POST,TRACE"
'Aegis(1)=".aspx,C:WINNTMicrosoft.NETFrameworkv1.1.4322aspnet_isapi.dll,1,GET,HEAD,
POST,DEBUG"
'Please use the format Aegis(Num)="" in parsing other files. Remember to define dim Aegis(Num)
'.htw,C:,3,GET,HEAD,POST
'.ida,C:,7,GET,HEAD,POST
'.idq,C:,7,GET,HEAD,POST
'.asp,C:,5,GET,HEAD,POST,TRACE
'.cer,C:,5,GET,HEAD,POST,TRACE
'.cdx,C:,5,GET,HEAD,POST,TRACE
'.asa,C:,5,GET,HEAD,POST,TRACE
'.idc,C:,5,GET,POST<br>
'.shtm C:,5,GET,POST<br>
'.shtml C:,5,GET,POST<br>
'.stm C:,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
=Aegis

'Show support scripting language
"Current site support parsing list: <br>"
For ValueIndex = 0 To UBound()
  ("ScriptMaps")(ValueIndex)
  "<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 Administrators group user permissions
'Function name: ListGroup(Computer)
'Usage: ListGroup (computer name)
'Example: Display 127.0.0.1 computer NT user group and user
'ListGroup "127.0.0.1"
'=======================================================
Function ListGroup(Computer)
"<p><b>The following is computer"&Computer&"system user group and user list</b></p>"
Set ComputerObj = GetObject("WinNT://"&Computer)
= Array("Group")
For Each Member in ComputerObj
"User Group:"&&"<br>"
 ListUser Computer,
Next
end Function

'List the specified user group users
Function ListUser(Computer,Group)
Set UserObj = GetObject("WinNT://"&Computer&"/"&Group)
For Each Member in
"&nbsp;&nbsp;&nbsp;&nbsp; Users in the group: "& &"<br>"
Next
End Function

IIS provides IIS Admin Objects, allowing users to manage IIS through programs. IIS Admin Objects are based on Microsoft Active Directory Service Interfaces (ADSI). It can be used by any programming language that supports Automation, such as VBScript/JScript in ASP, Visual Basic, Java, or C++.
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")
       = "D:newroot"
      
       Set IISOBJ=Nothing
%>
Note: The user must have sufficient permissions to IIS Metabase.
For more information about how to manage IIS with programs, you can refer to the following articles for MSDN:
Administering IIS Programmatically
/library/?url=/library/en-us/iisref/html/psdk/asp/
Read the full text (55) | Reply (0) | Quotation notice (0) | Edit