ASP create users, directories, and sites

Source: Internet
Author: User
Tags anonymous exit create directory ftp site iis port number root directory
Create | site


This lecture will use ADSI, the Active Directory service interface. You can find some relevant information in 15seconds.com.

1. Create user
The following code creates the user User1 on the standalone server white, the initial password User1, and uses ADSI.
Dim Username,userpass
Dim Odomain,ouser
Username = "User1"
Userpass = "User1"
Set odomain = GetObject ("Winnt://white")
Set ouser = odomain.create ("user", UserName)
If (err.number = 0) Then
Ouser.setinfo
Ouser.setpassword Userpass
Ouser.setinfo
Else
WScript.Echo "Create User" & UserName & "Error!" "
End If
Set ouser = Nothing
Set Odomain = Nothing

2. Create a table of contents
To create a directory using FileSystemObject:
Dim Fsobject
Dim Tmpfolder
Set fsobject = WScript.CreateObject ("Scripting.FileSystemObject")
Tmpfolder = "D:\userdate\user1"
If not fsobject.folderexists (tmpfolder) Then
Fsobject.createfolder (Tmpfolder)
If err.number<>0 Then
WScript.Echo "Create Directory" & Tmpfolder & "Failed!" "
End If
End If
Note Before you create a directory, check that the directory exists and, if it exists, you do not have to create it.

3. Create a site
The following subroutine is responsible for creating a WWW site, the meaning of each parameter is: Site IP address, site root directory, site description, host name, port number, computer name (a move for localhost), whether to start immediately, anonymous access to use the account number, anonymous access to the password of the account used, The directory of the log file.
function returns the ordinal number of the site that was built in IIS (in IIS, all sites are numbered sequentially, the first is 1).
One invocation example: SiteID = Astcreatewebsite ("10.1.3.122", "D:\userdata\user1", "Www_user1", "" "," "," "," "LocalHost", True, "IUSR_ User1 "," 8iui%# "," D:\Logfiles ")

Function Astcreatewebsite (IPAddress, RootDirectory, ServerComment, HostName, Portnum, Computer, Start, Anonymoususername,anonymoususerpass,logfiledirectory)
Dim w3svc, WebServer, Newwebserver, Newdir
Dim bindings, bindingstring, Newbindings, Index, Siteobj, Bdone
On Error Resume Next
Err.Clear
Set w3svc = GetObject ("iis://" & Computer & "/w3svc")
If err.number <> 0 Then
WScript.Echo "Cannot Open:" & "iis://" & Computer & "/w3svc" & VbCrlf & "program will exit."
Wscript.Quit (1)
End If

bindingstring = IPAddress & ":" & Portnum & ":" & HostName
For each WebServer in W3SVC
If Webserver.class = "IIsWebServer" Then
Bindings = Webserver.serverbindings
If bindingstring = Bindings (0) Then
WScript.Echo "IP address Conflict:" & IPAddress &, please detect IP address!. "& VbCrlf &" Cancels the creation of this site. "
Exit Function
End If
End If
Next

Index = 1
Bdone = False

while (not bdone)
Err.Clear
Set siteobj = GetObject ("iis://" &Computer& "/w3svc/" & Index)
If (err.number = 0) Then
index = index + 1
Else
Err.Clear
Set newwebserver = w3svc. Create ("IIsWebServer", Index)
If (err.number <> 0) Then
index = index + 1
Else
Err.Clear
Set siteobj = GetObject ("iis://" &Computer& "/w3svc/" & Index)
If (err.number = 0) Then
Bdone = True
Else
index = index + 1
End If
End If
End If

If (Index > 10000) Then
WScript.Echo "It appears that you cannot create a site and the number of sites you are creating is:" &Index& "." & VbCrlf & "cancels creating this site. "
Exit Function
End If
Wend

newbindings = Array (0)
Newbindings (0) = bindingstring
Newwebserver.serverbindings = newbindings
Newwebserver.servercomment = ServerComment
Newwebserver.anonymoususername = AnonymousUserName
Newwebserver.anonymoususerpass = AnonymousUserPass
Newwebserver.keytype = "IIsWebServer"
Newwebserver.frontpageweb = True
Newwebserver.enabledefaultdoc = True
Newwebserver.defaultdoc = "default.htm, Default.asp, index.htm, index.asp"
Newwebserver.logfiledirectory = LogFileDirectory
Newwebserver.setinfo

Set newdir = newwebserver.create ("IIsWebVirtualDir", "ROOT")
Newdir.path = RootDirectory
Newdir.accessread = True
Newdir.appfriendlyname = "Application" & ServerComment
Newdir.appcreate True
Newdir.accessscript = True
Err.Clear
Newdir.setinfo
If (err.number = 0) Then
Else
WScript.Echo "The home directory was created with an error."
End If

If Start = True Then
Err.Clear
Set newwebserver = GetObject ("iis://" & Computer & "/w3svc/" & Index)
Newwebserver.start
If err.number <> 0 Then
WScript.Echo "Error starting site!"
Err.Clear
Else
End If
End If
Astcreatewebsite = Index
End Function

The following function creates an FTP site:
Function Astcreateftpsite (IPAddress, RootDirectory, ServerComment, HostName, Portnum, Computer, Start, LogFileDirectory)
Dim msftpsvc, Ftpserver, Newftpserver, Newdir
Dim bindings, bindingstring, Newbindings, Index, Siteobj, Bdone
On Error Resume Next
Err.Clear
Set msftpsvc = GetObject ("iis://" & Computer & "/msftpsvc")
If err.number <> 0 Then
WScript.Echo "Cannot Open:" & "iis://" & Computer & "/msftpsvc" & VbCrlf & "program will exit."
Wscript.Quit (1)
End If

bindingstring = IPAddress & ":" & Portnum & ":" & HostName
For each ftpserver in MSFTPSVC
If ftpserver.class= "IIsFtpServer" Then
Bindings = Ftpserver.serverbindings
If bindingstring = Bindings (0) Then
WScript.Echo "IP address Conflict:" & IPAddress &, please detect IP address!. "& VbCrlf &" Cancels the creation of this site. "
Exit Function
End If
End If
Next

Index = 1
Bdone = False

while (not bdone)
Err.Clear
Set siteobj = GetObject ("iis://" &Computer& "/msftpsvc/" & Index)
If (err.number = 0) Then
index = index + 1
Else
Err.Clear
Set newftpserver = msftpsvc. Create ("IIsFtpServer", Index)
If (err.number <> 0) Then
index = index + 1
Else
Err.Clear
Set siteobj = GetObject ("iis://" &Computer& "/msftpsvc/" & Index)
If (err.number = 0) Then
Bdone = True
Else
index = index + 1
End If
End If
End If

If (Index > 10000) Then
WScript.Echo "It appears that you cannot create a site and the number of sites you are creating is:" &Index& "." & VbCrlf & "cancels creating this site. "
Exit Function
End If
Wend

newbindings = Array (0)
Newbindings (0) = bindingstring
Newftpserver.serverbindings = newbindings
Newftpserver.servercomment = ServerComment
Newftpserver.allowanonymous = False
Newftpserver.accesswrite = True
Newftpserver.accessread = True
Newftpserver.dontlog = False
Newftpserver.logfiledirectory = LogFileDirectory
Newftpserver.setinfo

Set newdir = newftpserver.create ("IIsFtpVirtualDir", "ROOT")
Newdir.path = RootDirectory
Newdir.accessread = True
Err.Clear
Newdir.setinfo
If (err.number = 0) Then
Else
WScript.Echo "The home directory was created with an error."
End If

If Start = True Then
Err.Clear
Set newftpserver = GetObject ("iis://" & Computer & "/msftpsvc/" & Index)
Newftpserver.start
If err.number <> 0 Then
WScript.Echo "Error starting site!"
Err.Clear
Else
End If
End If
Astcreateftpsite = Index
End Function




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.