|
基于ADSI的NT帐号及Exchange Server帐号申请及验证模块源代码
1.安装ADSI2.5 2.创建一个新的ActiveX DLL工程,工程名:RbsBoxGen,类名:NTUserManager 3.执行工程-引用将下列库选上: Active DS Type Library Microsoft Active Server Pages Object Library 4.添加一个模块,代码如下: '模块 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' '' ADSI Sample to create and delete Exchange 5.5 Mailboxes '' '' Richard Ault, Jean-Philippe Balivet, Neil Wemple -- 1998 '' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Option Explicit
' Mailbox property settings Public Const LOGON_CMD = "logon.cmd" Public Const INCOMING_MESSAGE_LIMIT = 1000 Public Const OUTGOING_MESSAGE_LIMIT = 1000 Public Const WARNING_STORAGE_LIMIT = 8000 Public Const SEND_STORAGE_LIMIT = 12000 Public Const REPLICATION_SENSITIVITY = 20 Public Const COUNTRY = "US"
' Mailbox rights for Exchange security descriptor (home made) Public Const RIGHT_MODIFY_USER_ATTRIBUTES = &H2 Public Const RIGHT_MODIFY_ADMIN_ATTRIBUTES = &H4 Public Const RIGHT_SEND_AS = &H8 Public Const RIGHT_MAILBOX_OWNER = &H10 Public Const RIGHT_MODIFY_PERMISSIONS = &H80 Public Const RIGHT_SEARCH = &H100
' win32 constants for security descriptors (from VB5 API viewer) Public Const ACL_REVISION = (2) Public Const SECURITY_DESCRIPTOR_REVISION = (1) Public Const SidTypeUser = 1
Type ACL AclRevision As Byte Sbz1 As Byte AclSize As Integer AceCount As Integer Sbz2 As Integer End Type
Type ACE_HEADER AceType As Byte AceFlags As Byte AceSize As Long End Type
Type ACCESS_ALLOWED_ACE Header As ACE_HEADER Mask As Long SidStart As Long End Type
Type SECURITY_DESCRIPTOR Revision As Byte Sbz1 As Byte Control As Long Owner As Long Group As Long Sacl As ACL Dacl As ACL End Type
' Just an help to allocate the 2dim dynamic array Private Type mySID x() As Byte End Type
' Declares : modified from VB5 API viewer Declare Function InitializeSecurityDescriptor Lib "advapi32.dll" _ (pSecurityDescriptor As SECURITY_DESCRIPTOR, _ ByVal dwRevision As Long) As Long
Declare Function SetSecurityDescriptorOwner Lib "advapi32.dll" _ (pSecurityDescriptor As SECURITY_DESCRIPTOR, _ pOwner As Byte, _ ByVal bOwnerDefaulted As Long) As Long
Declare Function SetSecurityDescriptorGroup Lib "advapi32.dll" _ (pSecurityDescriptor As SECURITY_DESCRIPTOR, _ pGroup As Byte, _ ByVal bGroupDefaulted As Long) As Long
Declare Function SetSecurityDescriptorDacl Lib "advapi32.dll" _ (pSecurityDescriptor As SECURITY_DESCRIPTOR, _ ByVal bDaclPresent As Long, _ pDacl As Byte, _ ByVal bDaclDefaulted As Long) As Long
Declare Function SetSecurityDescriptorSacl Lib "advapi32.dll" _ (pSecurityDescriptor As SECURITY_DESCRIPTOR, _ ByVal bSaclPresent As Long, _ pSacl As Byte, _ ByVal bSaclDefaulted As Long) As Long
Declare Function MakeSelfRelativeSD Lib "advapi32.dll" _ (pAbsoluteSecurityDescriptor As SECURITY_DESCRIPTOR, _ pSelfRelativeSecurityDescriptor As Byte, _ ByRef lpdwBufferLength As Long) As Long
Declare Function GetSecurityDescriptorLength Lib "advapi32.dll" _ (pSecurityDescriptor As SECURITY_DESCRIPTOR) As Long
Declare Function IsValidSecurityDescriptor Lib "advapi32.dll" _ (pSecurityDescriptor As Byte) As Long
Declare Function InitializeAcl Lib "advapi32.dll" _ (pACL As Byte, _ ByVal nAclLength As Long, _ ByVal dwAclRevision As Long) As Long
Declare Function AddAccessAllowedAce Lib "advapi32.dll" _ (pACL As Byte, _ ByVal dwAceRevision As Long, _ ByVal AccessMask As Long, _ pSid As Byte) As Long
Declare Function IsValidAcl Lib "advapi32.dll" _ (pACL As Byte) As Long
Declare Function GetLastError Lib "kernel32" _ () As Long
Declare Function LookupAccountName Lib "advapi32.dll" _ Alias "LookupAccountNameA" _ (ByVal IpSystemName As String, _ ByVal IpAccountName As String, _ pSid As Byte, _ cbSid As Long, _ ByVal ReferencedDomainName As String, _ cbReferencedDomainName As Long, _ peUse As Integer) As Long
Declare Function NetGetDCName Lib "NETAPI32.DLL" _ (ServerName As Byte, _ DomainName As Byte, _ DCNPtr As Long) As Long Declare Function NetApiBufferFree Lib "NETAPI32.DLL" _ (ByVal Ptr As Long) As Long Declare Function PtrToStr Lib "kernel32" _ Alias "lstrcpyW" (RetVal As Byte, ByVal Ptr As Long) As Long
Declare Function GetLengthSid Lib "advapi32.dll" _ (pSid As Byte) As Long
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' '' Create_NT_Account() -- creates an NT user account '' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function Create_NT_Account(strDomain As String, _ strAdmin As String, _ strPassword As String, _ UserName As String, _ FullName As String, _ NTServer As String, _ strPwd As String, _ strRealName As String) As Boolean
Dim oNS As IADsOpenDSObject Dim User As IADsUser Dim Domain As IADsDomain
On Error GoTo Create_NT_Account_Error
Create_NT_Account = False If (strPassword = "") Then strPassword = "" End If Set oNS = GetObject("WinNT:") Set Domain = oNS.OpenDSObject("WinNT://" & strDomain, strDomain & "\" & strAdmin, strPassword, 0) Set User = Domain.Create("User", UserName) With User .Description = "ADSI 创建的用户" .FullName = strRealName 'FullName '.HomeDirectory = "\\" & NTServer & "\" & UserName '.LoginScript = LOGON_CMD .SetInfo ' First password = username .SetPassword strPwd End With Debug.Print "Successfully created NT Account for user " & UserName Create_NT_Account = True Exit Function
Create_NT_Account_Error: Create_NT_Account = False Debug.Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred creating NT account for user " & UserName
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' '' Delete_NT_Account() -- deletes an NT user account '' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function Delete_NT_Account(strDomain As String, _ strAdmin As String, _ &nb [1] [2] [3] [4] [5] 下一页
|