请问如何取出win2000域活动目录中组的名称及其包含的所有用户名称(域登录名),急我尝试了LDAP的方式,可是只能访问各Container(存放部门信息)中组的名称和人员姓名,不知道如何访问组中的用户;也不知道如何取出用户的登录名称Dim oContainer
Set oContainer = GetObject("LDAP://ou=质量部,OU=杭州和利时,DC=hollysys,DC=net")
Dim oUser
For Each oUser In oContainer If Not IsEmpty(oUser.name) Then
    Debug.Print oUser.Class            ' 不知道取登录名用什么属性?
    Debug.Print oUser.Name
    'Debug.Print oUser.DisplayName
    'Debug.Print oUser.Description
    'Debug.Print oUser.Get("sn")
    'Debug.Print oUser.sn
    if LCase(oUser.Class) = "group" then
        // 如何取出人员信息(登录帐号)
    end if
End If
Set oContainer = Nothing或者这种方法行不通,那还有别的方法?

解决方案 »

  1.   

    获取网上邻居里的计算机名这是转自以前网友的贴,我也忘记是谁写的了,我自已没测试过。
    option explicit
    private const resource_connected as long = &h1&
    private const resource_globalnet as long = &h2&
    private const resource_remembered as long = &h3&private const resourcedisplaytype_directory& = &h9
    private const resourcedisplaytype_domain& = &h1
    private const resourcedisplaytype_file& = &h4
    private const resourcedisplaytype_generic& = &h0
    private const resourcedisplaytype_group& = &h5
    private const resourcedisplaytype_network& = &h6
    private const resourcedisplaytype_root& = &h7
    private const resourcedisplaytype_server& = &h2
    private const resourcedisplaytype_share& = &h3
    private const resourcedisplaytype_shareadmin& = &h8
    private const resourcetype_any as long = &h0&
    private const resourcetype_disk as long = &h1&
    private const resourcetype_print as long = &h2&
    private const resourcetype_unknown as long = &hffff&
    private const resourceusage_all as long = &h0&
    private const resourceusage_connectable as long = &h1&
    private const resourceusage_container as long = &h2&
    private const resourceusage_reserved as long = &h80000000
    private const no_error = 0
    private const error_more_data = 234 'l    // dderror
    private const resource_enum_all as long = &hffff
    private type netresource
        dwscope as long
        dwtype as long
        dwdisplaytype as long
        dwusage as long
        plocalname as long
        premotename as long
        pcomment as long
        pprovider as long
    end type
    private type netresource_real
        dwscope as long
        dwtype as long
        dwdisplaytype as long
        dwusage as long
        slocalname as string
        sremotename as string
        scomment as string
        sprovider as string
    end type
    private declare function wnetaddconnection2 lib "mpr.dll" alias "wnetaddconnection2a" (lpnetresource as netresource, byval lppassword as string, byval lpusername as string, byval dwflags as long) as long
    private declare function wnetopenenum lib "mpr.dll" alias "wnetopenenuma" (byval dwscope as long, byval dwtype as long, byval dwusage as long, lpnetresource as any, lphenum as long) as long
    private declare function wnetenumresource lib "mpr.dll" alias "wnetenumresourcea" (byval henum as long, lpccount as long, lpbuffer as netresource, lpbuffersize as long) as long
    private declare function wnetcloseenum lib "mpr.dll" (byval henum as long) as long
    private declare function varptrany lib "vb40032.dll" alias "varptr" (lpobject as any) as long
    private declare sub copymem lib "kernel32" alias "rtlmovememory" (lpto as any, lpfrom as any, byval llen as long)
    private declare sub copymembyptr lib "kernel32" alias "rtlmovememory" (byval lpto as long, byval lpfrom as long, byval llen as long)
    private declare function lstrcpy lib "kernel32" alias "lstrcpya" (byval lpstring1 as string, byval lpstring2 as any) as long
    private declare function lstrlen lib "kernel32" alias "lstrlena" (byval lpstring as any) as long
    sub main()
        const max_resources = 256
        const not_a_container = -1    dim bfirsttime as boolean
        dim lreturn as long
        dim henum as long
        dim lcount as long
        dim lmin as long
        dim llength as long
        dim l as long
        dim lbuffersize as long
        dim llastindex as long
        dim unetapi(0 to max_resources) as netresource
        dim unet() as netresource_real
        bfirsttime = true
        do
            if bfirsttime then
                lreturn = wnetopenenum(resource_globalnet, resourcetype_any, resourceusage_all, byval 0&, henum)
                bfirsttime = false
            else
                if unet(llastindex).dwusage and resourceusage_container then
                    lreturn = wnetopenenum(resource_globalnet, resourcetype_any, resourceusage_all, unet(llastindex), henum)
                else
                    lreturn = not_a_container
                    henum = 0
                end if
                llastindex = llastindex + 1
            end if
            if lreturn = no_error then
                lcount = resource_enum_all
                do
                    lbuffersize = ubound(unetapi) * len(unetapi(0)) / 2
                    lreturn = wnetenumresource(henum, lcount, unetapi(0), lbuffersize)
                    if lcount > 0 then
                        redim preserve unet(0 to lmin + lcount - 1) as netresource_real
                        for l = 0 to lcount - 1
                            'each resource will appear here as unet(i)
                            unet(lmin + l).dwscope = unetapi(l).dwscope
                            unet(lmin + l).dwtype = unetapi(l).dwtype
                            unet(lmin + l).dwdisplaytype = unetapi(l).dwdisplaytype
                            unet(lmin + l).dwusage = unetapi(l).dwusage
                            if unetapi(l).plocalname then
                                llength = lstrlen(unetapi(l).plocalname)
                                unet(lmin + l).slocalname = space$(llength)
                                copymem byval unet(lmin + l).slocalname, byval unetapi(l).plocalname, llength
                            end if
                            if unetapi(l).premotename then
                                llength = lstrlen(unetapi(l).premotename)
                                unet(lmin + l).sremotename = space$(llength)
                                copymem byval unet(lmin + l).sremotename, byval unetapi(l).premotename, llength
                            end if
    if unetapi(l).pcomment then
                                llength = lstrlen(unetapi(l).pcomment)
                                unet(lmin + l).scomment = space$(llength)
                                copymem byval unet(lmin + l).scomment, byval unetapi(l).pcomment, llength
                            end if
                            if unetapi(l).pprovider then
                                llength = lstrlen(unetapi(l).pprovider)
                                unet(lmin + l).sprovider = space$(llength)
                                copymem byval unet(lmin + l).sprovider, byval unetapi(l).pprovider, llength
                            end if
                        next l
                    end if
                    lmin = lmin + lcount
                loop while lreturn = error_more_data
            end if
            if henum then
                l = wnetcloseenum(henum)
            end if
        loop while llastindex < lmin
        if ubound(unet) > 0 then
            for l = 0 to ubound(unet)
                select case unet(l).dwdisplaytype
                    case resourcedisplaytype_directory&
                        debug.print "directory...",
                    case resourcedisplaytype_domain
                        debug.print "domain...",
                    case resourcedisplaytype_file
                        debug.print "file...",
                    case resourcedisplaytype_generic
                        debug.print "generic...",
                    case resourcedisplaytype_group
                        debug.print "group...",
                    case resourcedisplaytype_network&
                        debug.print "network...",
                    case resourcedisplaytype_root&
                        debug.print "root...",
                    case resourcedisplaytype_server
                        debug.print "server...",
                    case resourcedisplaytype_share
                        debug.print "share...",
                    case resourcedisplaytype_shareadmin&
                        debug.print "shareadmin...",
                end select
                debug.print unet(l).sremotename, unet(l).scomment
            next l
        end if