Original article: Welcome reprint, Reprint, please retain the author name and source
Author: Jacksonluo
One: Pre-server configuration for IIS (other security is not mentioned) (take freeshare.com.cn as an example)
1. Create the (freeshare.com.cn) computer username for the domain and set a secure password
2. Create directory folders for this domain (D:\Inetpub\freeshare.com.cn)
3. Set Directory access permissions, freeshare.com.cn Full Control of the directory (provide anonymous users access to the site)
4. Create a separate application process pool for the description of the domain name (company name), create a separate application process pool for each virtual host, and protect individual site problems from running the entire server. When creating a process pool, you can set the user name and password separately and set the CPU, number of connections, and so on. The default is used here.
5. Create a virtual host, select the application process pool created above, select Anonymous user freeshare.com.cn in directory security, and set the password that is identical to the computer creation freeshare.com.cn username, must be consistent, otherwise the Web site cannot be accessed.
OK, this is for each virtual host to do, then these are not all of the artificial to complete it? The answer is no, Windows can also implement scripting Oh, (oh, I also do not know the original)
Then you can not do it by hand, with what? Let's use VBScript script.
Two: script to complete the above creation of the virtual host action
Save As Createsiglewebsite.vbs
Copy Code code as follows:
Dim sitenum,ipaddr,portnum,lencomputer,webservercomment,logdirectory
Dim User_password,groupname,tmpfolder,usernamecomp,webserverautostart
Dim Webanonymoususername
Webservercomment= "Company Name" ' website description, computer user description and full name use this variable
usernamecomp= "freeshare.com.cn" ' Computer username and user directory using this variable
HostName = ": 80:www.freeshare.com.cn" ' Virtual Host site host name
Webanonymoususername = Getcomputer () & "\ &usernamecomp" virtual host anonymous user (preceded by the local computer name)
User_password = "**********" ' Computer User and anonymous user password.
GroupName = "Guests" ' Group of computer users
ipaddr = "" ' Computer IP address, can be null
Tmpfolder = "D:\inetpub\" &usernamecomp ' target directory
Lencomputer = Len (Getcomputer ()) +1 ' computer name + ' length of '
Portnum = "80" Virtual host port
Webserverautostart = "true" to run true and false after creating a virtual host
Logdirectory = "" ' Log Directory
' Detect if the user's computer account exists
If not CheckUser (usernamecomp) Then
' Add this Computer user account
AddUser Getcomputer (), Usernamecomp,user_password,webservercomment,webservercomment,groupname
Else
WScript.Echo "This computer user name also exists ...... ..."
End If
' Create user home directory
Createfiledirectory (Tmpfolder)
' Modify the access rights of the user's home directory
Setntfsdirectoryperssion (Usernamecomp)
' Create the application process pool
Createapppool webservercomment
' Create a virtual host site
Createwebsite Getcomputer (), Ipaddr,hostname,tmpfolder,logdirectory,webservercomment,usernamecomp,user_password, Webserverautostart
' Buildnum = buildnum+1
' WScript.Echo ' ============================================== "&BuildNum&" ============================== ==============="
' Create a site application pool for each IIS Virtual host application site
Function Createapppool (StrName)
On Error Resume Next
Err.Clear
Set objapppoolsexist = GetObject ("iis://" &getcomputer () & "/w3svc/apppools" &strname)
If Err.Number = 0 Then
WScript.Echo "This application process pool has been created .... ..."
Set objapppoolsexist = Nothing
Exit Function
Else
Set objapppools = GetObject ("iis://" & Getcomputer () & "/w3svc/apppools")
Err.Clear
Set Objapppool = objapppools.create ("IIsApplicationPool", StrName)
If Err.Number = 0 Then
Objapppool.apppoolidentitytype = 2 ' runs as NT Authority\Network 3 Run as specific user account 1 runs as NT Authority\loc AL SERVICE 0 runs as NT authority\system
Objapppool.setinfo
If Err. Number = 0 Then
Createapppool = True
WScript.Echo "Application" &strName& "Create success!" "
Else
Createapppool = False
WScript.Echo "Application &strName&" creation failed! "
End If
Else
Createapppool = False
End If
End If
Set Objapppool = Nothing
Set Objapppools = Nothing
Set objapppoolsexist = Nothing
End Function
Function Createwebsite (Strcomputer,ipaddr,webserverbingings,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://" & Getcomputer () & "/w3svc")
If err.number <> 0 Then ' Show error tips
WScript.Echo "Cannot Open:" & "iis://" & Getcomputer () & "/w3svc"
Exit Function
End If
' Detects if there is a site with the same IP address, port, and host name
bindingstring = ipaddr & webserverbingings
For each WebServer in W3SVC
If Webserver.class = "IIsWebServer" Then
Bindings = Webserver.serverbindings
If bindingstring = Bindings (0) Then
WScript.Echo "Virtual Host: & HostName &", existing, unable to create ...
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://" &getcomputer () & "/w3svc/" &sitenum) ' loads the specified site
If (err.number = 0) Then
' WScript.Echo ' step_1 site ' &SiteNum& ' presence '
Sitenum = sitenum + 1
Else
' WScript.Echo ' step_1 site ' &SiteNum& ' does not exist '
Err.Clear
Set newwebserver = w3svc. Create ("IIsWebServer", Sitenum) ' Creates a specified site
If (err.number <> 0) Then
WScript.Echo sitenum& "Create Failed"
Sitenum = sitenum + 1
Else
WScript.Echo sitenum& "Create Success"
Bdone = True
End If
End If
If (Sitenum > 1000) Then ' server maximum number of sites created
WScript.Echo "Exceeds the maximum number of server creation sites, the number of sites being created is:" &SiteNum&. "
Exit Function
End If
Wend
' Basic configuration of the site
newbindings = Array (0)
Newbindings (0) = bindingstring
Newwebserver.serverbindings = newbindings
Newwebserver.servercomment= webservercomment
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,index.html,default.html"
newwebserver.logfiledirectory= logdirectory
Newwebserver.setinfo
Set newdir = newwebserver.create ("IIsWebVirtualDir", "ROOT")
Newdir.path = Websitedirectory
Newdir.accessread = True
Newdir.appfriendlyname = Webservercomment
Newdir.appcreate True
Newdir.accessscript = True
NEWDIR.AUTHNTLM = True
newdir.appisolated = "2"
Newdir.apppoolid = Webservercomment
' Newdir.appcreate3 2,websiteinfo,false
Newdir.authflags = "AuthAnonymous | AUTHNTLM "' Integrated Windows authentication
Err.Clear
Newdir.setinfo
If (err.number <> 0) Then
WScript.Echo "The home directory was created with an error."
Exit Function
End If
If startorstop = True Then
Err.Clear
Set newwebserver = GetObject ("iis://" & Getcomputer () & "/w3svc/" & Sitenum)
Newwebserver.start
If err.number <> 0 Then
WScript.Echo "Error starting site!"
Err.Clear
End If
End If
WScript.Echo "Site created successfully, the site number is:" & Sitenum & ", the domain name is:" & webserverbingings
' Setcpulimitvar strcomputer,sitenum,100 ' calls CPU maximum usage
End Function
Function Getcomputer ()
Dim objnet
Set objnet = CreateObject ("Wscript.Network")
Getcomputer= Objnet.computername
Set objnet = Nothing
End Function
Function createfiledirectory (UserName)
Set Fsobject = CreateObject ("Scripting.FileSystemObject")
On Error Resume Next
Err.Clear
If not fsobject.folderexists (UserName) Then
Fsobject.createfolder (UserName)
If err.number<>0 Then
WScript.Echo "Create Directory" & UserName & "Failed!" "
Else
WScript.Echo "Create Directory" & UserName & "Success!" "
End If
Else
WScript.Echo "Directory" & UserName & "already exists, you cannot create!" "
End If
Set Fsobject = Nothing
End Function
Function setntfsdirectoryperssion (sourcedirectory)
Dim wshshell,oexec
Dim exedirectory
Exedirectory = "C:\Program files\resource kit\xcacls.exe C:\Inetpub\"
Orders_exec = exedirectory&sourcedirectory& "/e/t/g" &sourceDirectory& ": F; F
Set WshShell = CreateObject ("Wscript.Shell")
Set oexec = wshshell.exec (orders_exec)
If oexec.status = 0 Then
WScript.Echo "Command executed successfully! "
Else
WScript.Echo Command Execution failed! Insufficient permissions or the program cannot run in DOS
End If
Set wshshell= Nothing
End Function
Function CheckUSer (struser)
On Error Resume Next
' Check if domain is already part of username passed to function
If InStr (struser, "\") = 0 Then
Set objgrp = GetObject ("winnt://" & Getcomputer () & "/" & struser & ", user")
Else
Set objgrp = GetObject ("winnt://" & Replace (struser, "\", "/") & "user")
End If
If Err.Number = 0 Then
CheckUSer = True
Else
CheckUSer = False
End If
Set objgrp = Nothing
On Error Goto 0
End Function
Function AddUser (Computer,username,password,fullname,info,groupname)
DIM Intreturn,fsobject
On Error Resume Next
' Execute create account command
Set computeraccoutobj = GetObject ("winnt://" &getcomputer () & "/" &UserName& ", user")
If Err.number=0 Then
WScript.Echo username& "Computer User already exists ..."
Else
Set computerobj = GetObject ("winnt://" &getcomputer ())
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 xor &h0040 ' &h20000 (User must change password at next login) &h0040 (user must not change password) &h10000 (password permanently correct) & Amp H0002 (account temporarily inactive)
Newuser.setinfo
WScript.Echo "Account" &UserName& "Create success!" "
Set Objselectgroup = GetObject ("winnt://" & Getcomputer () & "/guests,group")
Set Objadduser = GetObject ("winnt://" & Getcomputer () & "/" & UserName & ", user")
Objselectgroup.add (Objadduser.adspath)
End If
Set computerobj=nothing
Set computeraccoutobj = Nothing
Set computeraccoutgroupobj = Nothing
End Function
After the program is finished, you can simply save the above program to the *.vbs Windows directory and execute it directly.
It uses a xcacls to modify NTFS permissions, you can download from the Microsoft Official website, you can also visit the http://www.microsoft.com/windows2000/techinfo/reskit/ tools/existing/xcacls-o.asp download installation is available.
See also part of the IIS Server Backup transfer solution (II)