注册 | 登录
收藏 | 帮助
热门文章
编辑推荐
相关文章  
网友经验:手工剿灭木马“advapi
教你穿透ADSL路由入侵内网
一分钟攻破ADSL盗遍宽带密码
宽带上网 小心有诈 浅谈ADSL入侵
ADSL用户注意的安全问题
电信ADSL用户必读:ADSL账号密码
震惊!远程盗取ADSL帐号很简单(
如果密码是admin 小心你的信息安
DNS 系统设定例--8.[Rev] 特殊网
DNS 系统设定例--9.[Rev] 特殊网
您现在的位置: 顶尖设计 >> IT学院 >> 编程开发 >> VB >> 文章正文
基于ADSI的NT帐号及Exchange Server帐号申请及验证模块源代码
作者:zhengsb  来源:CSDN  点击:  更新:2006-12-19
简介:

基于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] 下一页






  • 上一篇文章:
  • 下一篇文章:
  • 分享此文:该页面添加到 Mister Wong 添加到雅虎Yahoo!收藏 Add to:Del.icio.us Post to Furl Digg this 添加到Google书签 reddit spurl blogmarks 365Key 评论  收藏  分享  打印
     我来说两句
    姓名:       验证码:   
    主页: 
    评分: 1分 2分 3分 4分 5分
    本频道近期热评文章:
      关于我们 | 联系我们 | 站点地图 | 广告投放 | 友情链接 | 在线留言 | 版权申明
    版权所有 © 2004-2007 顶尖设计(bobd.cn)
    未经授权禁止转载,摘编,复制本站内容或建立镜像. 沪ICP备07504942号 
    网络110
    报警服务