Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Get NT users from Win98

Thanks for your answer, but i forgave to say that i'm running on a win98 client...
and some api don't works...

Salvino

Craig Clearman <chclear@nospam.please> wrote:
>Salvino,
>
>>How can i get a list of all NT users in a NT domain?
>
>You're running on NT, I assume? If so, here's the relevant portion of
>a users collection class.
>
>'==================================================
>' Module: CUsers
>'
>' Description: This is a collection of the
>' users defined for a particular machine.
>'
>' Programmer: Craig Clearman
>'
>' Revision History:
>' 30 Apr 96 - Module Created
>'
>'==================================================
>
>'==================================================
>' Private API Structures
>'==================================================
>Private Type USER_INFO_0
> psUserName As Long
>End Type
>
>'==================================================
>' Private API Declarations
>'==================================================
>Private Declare Sub CopyMem _
> Lib "kernel32" Alias "RtlMoveMemory" ( _
> pTo As Any, _
> pFrom As Any, _
> ByVal nCount As Long)
>
>Private Declare Function lstrlenW _
> Lib "kernel32" ( _
> ByVal pString As Long) As Long
>
>Private Declare Function NetApiBufferFree _
> Lib "netapi32" ( _
> ByVal pBuffer As Long) As Long
>
>Private Declare Function NetUserEnum _
> Lib "netapi32" ( _
> ByVal psServer As Long, _
> ByVal hLevel As Long, _
> ByVal hFilter As Long, _
> pBuffer As Long, _
> ByVal nMaxLength As Long, _
> nEntries As Long, _
> nTotal As Long, _
> hResume As Long) As Long
>
>'==================================================
>' Private API Constants
>'==================================================
>Private Const ERROR_SUCCESS As Long = 0&
>Private Const ERROR_MORE_DATA As Long = 234&
>
>'==================================================
>' Private Member Data
>'==================================================
>Private m_usersCollection As Collection
>
>'==================================================
>' Private Procedures
>'==================================================
>
>'==================================================
>' Procedure: LoadUsers
>'
>' Description: This procedure will walk through
>' the users on a particular machine and add them
>' onto the collection.
>'==================================================
>Private Sub LoadUsers()
>
>Const MAX_SIZE As Long = 2048&
>
>Dim uUsers() As USER_INFO_0
>Dim hReturn As Long
>Dim pBuffer As Long
>Dim nEntries As Long
>Dim nTotal As Long
>Dim hResume As Long
>Dim iUser As Long
>Dim userEnum As CUser
>Dim sUserID As String
>
>If m_usersCollection Is Nothing Then
> Set m_usersCollection = New Collection
> Do
> If Len(m_sServer) Then
> hReturn = NetUserEnum(StrPtr(m_sServer), 0&, 0&, pBuffer,
>MAX_SIZE, nEntries, nTotal, hResume)
> Else
> hReturn = NetUserEnum(ByVal 0&, 0&, 0&, pBuffer, MAX_SIZE,
>nEntries, nTotal, hResume)
> End If
> If hReturn = ERROR_MORE_DATA Or hReturn = ERROR_SUCCESS Then
> If pBuffer Then
> If nEntries Then
> ReDim uUsers(0 To nEntries - 1) As USER_INFO_0
> CopyMem uUsers(0), ByVal pBuffer, Len(uUsers(0)) *
>nEntries
> For iUser = 0 To nEntries - 1
> Set userEnum = New CUser
> With uUsers(iUser)
> sUserID = WidePointerToString(.psUserName)
> End With
> userEnum.Init sUserID
> m_usersCollection.Add userEnum, sUserID
> Next iUser
> End If
> NetApiBufferFree pBuffer
> pBuffer = 0&
> End If
> End If
> Loop While hReturn = ERROR_MORE_DATA
>End If
>
>End Sub
>
>'==================================================
>' Procedure: WidePointerToString
>'
>' Inputs: pString A pointer to a Unicode
>' string
>'
>' Returns: String
>'
>' Description: This procedure will turn a pointer
>' representation of a string, often from API functions,
>' and turn it into a string that VB can understand.
>'==================================================
>Private Function WidePointerToString(ByVal pString As Long) As String
>
>Dim sString As String
>Dim nChars As Long
>
>If pString Then
> 'How many characters do I need?
> nChars = lstrlenW(pString)
> If nChars Then
> sString = Space$(nChars)
> 'Multiply the characters by two, to get
> ' the Unicode size in bytes.
> CopyMem ByVal StrPtr(sString), ByVal pString, nChars * 2
> End If
>End If
>
>WidePointerToString = sString
>
>End Function
>
>Ciao, Craig
>
[6304 byte] By [salvino] at [2007-11-10 0:19:39]
# 1 Re: Get NT users from Win98
Salvino,

>Thanks for your answer, but i forgave to say that i'm running on a win98 client...
>and some api don't works...

On Win98, your choices are limited. There is a remote administration
kit that is distributed that can help you -- it packages svrapi.dll,
which holds ANSI versions of the Net* functions. Without that, you can
still use VB4/16-bit to call the original 16-bit netapi functions. Or,
you can make a DCOM server that runs on your NT box to return the
information to you.

However, there is no native 32-bit APIs that are available on all
Win9x boxes.

Ciao, Craig
Craig Clearman at 2007-11-11 20:04:49 >
# 2 Re: Get NT users from Win98
Salvino,

>Thanks for your answer, but i forgave to say that i'm running on a win98 client...
>and some api don't works...

On Win98, your choices are limited. There is a remote administration
kit that is distributed that can help you -- it packages svrapi.dll,
which holds ANSI versions of the Net* functions. Without that, you can
still use VB4/16-bit to call the original 16-bit netapi functions. Or,
you can make a DCOM server that runs on your NT box to return the
information to you.

However, there is no native 32-bit APIs that are available on all
Win9x boxes.

Ciao, Craig
Craig Clearman at 2007-11-11 20:05:54 >