使用ADSI對IIS進行管理需要OP4
而對NT要進行ADSI管理則需要NTLM
NTLM提供以下幾個對象: Domain, Group, and User.
通過domain對象你可以增加groups和users.
警告:
以下的例子都將改變NT訪問權限數據庫;任意增加和改變NT用戶的權限
使用前請仔細閱讀,請只在測試的機器上運行這些程序,只到你掌握了NTLM
的工作原理為止。千萬不要危害到真正主機的安全。
只有擁有Administrator或則Operator權限的人才能夠在運行IIS機器上
更改NT的用戶數據庫。所以,使用Anonymous權限登錄是沒有權限的。
當然如果使用SSL的話也能夠保證安全性。
例子如下:
新建一個用戶:
可以在一個獨立的服務器上,也可以在一個主域服務器上新增用戶
<%
On Error Resume Next
strDomain="MACHINENAME"
strUser="jdoe"
Set oDomain = GetObject("WinNT://" & strDomain)
Set oUser = oDomain.Create ("user", strUser)
If (err.number = 0) Then
oUser.SetInfo
oUser.SetPassword "mypassword"
oUser.SetInfo
Set oUser=Nothing
End If
Set oDomain=Nothing
%>
新增加一個組:
<%
strDomain="MACHINENAME"
strGroup="Unidentified"
Set oDomain = GetObject("WinNT://" & strDomain)
Set oGroup = oDomain.Create ("group", strGroup)
oGroup.SetInfo
Set oDomain=Nothing
Set oGroup=Nothing
%>
把一個用戶增加到一個組中.
<%
strDomain="MACHINENAME"
strUser="jdoe"
strGroup="Unidentified"
Set oDomain = GetObject("WinNT://" & strDomain)
Set oGroup = oDomain.GetObject("Group", strGroup)
oGroup.Add ("WinNT://" & strDomain & "/" & strUser)
Set oDomain=Nothing
Set oGroup=Nothing
%>
配置用戶信息
<%
strDomain="MACHINENAME"
strUser="jdoe"
Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser)
' Setting the Account Expiration to 30 days from today
dtExpirationDate=Now()
dtExpirationDate=DateAdd("d",30,dtExpirationDate)
oUser.AccountExpirationDate = dtExpirationDate
' Setting the Full Name of the User
oUser.FullName="Joe Doe"
oUser.SetInfo()
Set oUser=Nothing
%>
繼承用戶
<%
strDomain="MACHINENAME"
strGroup="Unidentified"
Set Group = GetObject("WinNT://" & strDomain & "/" & strGroup)
For Each Member in Group.Members
If (Member.Class="User") Then
' Here is where you would do
' something with the user
End If
Next
%>
當你是使用的NT5.0時,就不需要安裝NTLM了,因為NT5.0提供對ADSI的支持。