Link to home
Start Free TrialLog in
Avatar of jshafer
jshafer

asked on

create a list of users and contexts

Hi,
  I would like to be able to create a text file which lists all of the userids and contexts in a Directory.  I tried doing this with cx, but it doesn't seem to list the user objects.  Any idea?  If there are any inexpensive third party utilities that can do this, I am interested.
  Many Thanks,
Jeremy
Avatar of jshafer
jshafer

ASKER

(Oh yes, I am using NW 4.1)
I have code that allows me to list all users, with contexts, on a given Intranetware 4 server.  Is this what you are looking for? It uses the NW* calls in CLXWin32.Dll.

Can't get it until tomorrow, but let me know if this is useful.


Avatar of jshafer

ASKER

Yes, that would be very helpful.  I presume these are VB routines?
ASKER CERTIFIED SOLUTION
Avatar of brosenb0
brosenb0
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, I've been away unexpectedly.  If brosenb0 ans. isn't enough, I'll try to upload some VB code next week.
'Here's code that works for me...it lists all the servers in the
'debug window, getting their connection numbers...
'then matches one server name against a name you put in
'via an InputBox, and lists the active users on that server.
'Of course, you'll want to change the public const
' UserServerNameDefault to something on your system.
'Note: nConnMaxUsed on my system reports a number below
'the actual number of connections sometimes, so I've used
'the arbitrary figure of 250 max connections.
'
'Of course, this goes into a .bas module.  You don't need
'a form as long as sub Main is set as the default startup.

'I didn't wait to see if you rejected brosenb0's ans...
'I figure info exchange is more important than points.


Option Explicit
'UserIDs ... minimal code to get list of users

Declare Function NWCallsInit Lib "calwin32" _
   (notUsed1 As Any, notUsed2 As Any) As Long

Declare Function NWCCScanConnRefs Lib "CLXWIN32" _
   (scanIterator As Long, connRef As Long) As Long

Declare Function NWCCGetConnRefInfoString Lib "CLXWIN32" _
   Alias "NWCCGetConnRefInfo" (ByVal connRef As Long, _
   ByVal infoType As Long, _
   ByVal infoLen As Long, _
   ByVal buffer As String) As Long
   
Declare Function NWCCOpenConnByRef Lib "CLXWIN32" _
   (ByVal connRef As Long, _
   ByVal openState As Long, _
   ByVal Reserved As Long, _
         connHandle As Long) As Long
     
Declare Function NWGetFileServerInformation Lib "calwin32" ( _
        ByVal conn As Long, _
        ByVal serverName As String, _
        majorVer As Byte, _
        minVer As Byte, _
        rev As Byte, _
        maxConns As Integer, _
        maxConnsUsed As Integer, _
        connsInUse As Integer, _
        numVolumes As Integer, _
        SFTLevel As Byte, _
        TTSLevel As Byte) As Long

Declare Function NWGetConnectionInformation Lib "calwin32" ( _
   ByVal conn As Long, _
   ByVal connNum As Integer, _
   ByVal objName As String, _
   objType As Integer, _
   objID As Integer, _
   loginTime As Byte) As Long
   
Declare Function NWCCCloseConn Lib "CLXWIN32" _
   (ByVal connHandle As Long) As Long
   
Public Const SUCCESS As Long = &H0
   
Public Const NWCC_TRAN_TYPE_IPX = 1
Public Const NWCC_TRAN_TYPE_UDP = 2
Public Const NWCC_TRAN_TYPE_DDP = 3
Public Const NWCC_TRAN_TYPE_ASP = 4

Public Const NWCC_OPEN_LICENSED = 1
Public Const NWCC_OPEN_UNLICENSED = 2

Public Const NWCC_INFO_SERVER_NAME = 7
Public Const NW_MAX_SERVER_NAME_LEN As Long = 49
 
Public Const NetConnMax = 250
'max licensed conns to search
'...nConnMaxUsed...seems to be too low for me...
'change server name to your default
Public Const UserServerNameDefault = "MHS_MEDIA"
Public UserServerName$
Public UserServerConnRef As Long

Public Sub ListServers()
' Get connected servers
Dim lRet&, lIterator&, lConnRef&, lTemp&
Dim sBuff As String * NW_MAX_SERVER_NAME_LEN
Dim sSrvName As String
Do
   ' lIterator is initialized to zero automatically
   lRet = NWCCScanConnRefs(lIterator, lConnRef)
   If lRet <> SUCCESS Then Exit Do
   lRet = NWCCGetConnRefInfoString( _
      lConnRef, _
      NWCC_INFO_SERVER_NAME, _
      NW_MAX_SERVER_NAME_LEN, _
      sBuff)
   
   If lRet = SUCCESS Then
      lTemp = InStr(1, sBuff, vbNullChar)
      sSrvName = Left(sBuff, lTemp - 1)
      Debug.Print sSrvName
     
      If UCase(sSrvName) = UCase(UserServerName) Then _
         UserServerConnRef = lConnRef
   End If
Loop
End Sub

Private Sub ListUsers()
Dim i%, i1%, i2%, i3%
Dim hConn&, nConnRef&, objID%, nRetcode&
Dim nConnMaxUsed%, objType%
Dim strServerName As String * NW_MAX_SERVER_NAME_LEN
Dim strBuffer As String * 255
Dim strUserName As String, sTemp As String
Dim loginTime(7) As Byte
Dim b1 As Byte, b2 As Byte, b3 As Byte, b4 As Byte, b5 As Byte

nConnRef = UserServerConnRef 'the one selected by the user
nRetcode = NWCCOpenConnByRef(nConnRef, NWCC_OPEN_LICENSED, NWCC_TRAN_TYPE_IPX, hConn)
If nRetcode = SUCCESS Then
   nRetcode = NWGetFileServerInformation( _
      hConn, strBuffer, b1, b2, b3, i1, nConnMaxUsed, i2, i3, b4, b5)
   If nRetcode = SUCCESS Then
      '?? nConnMaxUsed seems to be less than needed sometimes...
      '   so use arbitrarily high number...
      For i = 0 To NetConnMax    'normal use: nConnMaxUsed here
         nRetcode = NWGetConnectionInformation(hConn, i, strBuffer, objType, objID, loginTime(0))
         If nRetcode = SUCCESS Then
            strBuffer = Left$(strBuffer, InStr(1, strBuffer, vbNullChar) - 1)
            strUserName = RTrim(strBuffer)
            Debug.Print strUserName
         End If
      Next i
   End If
   NWCCCloseConn (hConn)
End If
End Sub

Sub Main()
Dim lRetCode As Long
lRetCode = NWCallsInit(0, 0)
If lRetCode <> SUCCESS Then
   MsgBox "Unable to initialize NWCallsInit", _
      vbInformation, "Startup Problem"
   End
End If
UserServerName = InputBox("Server Name for UserList", _
   "Enter Server Name", UserServerNameDefault)
   
ListServers
ListUsers
Stop

End Sub


Avatar of jshafer

ASKER

This comment is for jtest.  Thanks for your post.  I ended up giving the points to brosenbo since he give me the response I really needed.  I tried the your code, and it gives me a list of connected users, what I was really hunting for was a list of all users and their contexts.

I do really like your code though, and wanted to say thanks for it.