Solved

Getting users login name

Posted on 2002-04-29
6
803 Views
Last Modified: 2008-02-01
I'm using the netware activeX controls to create a VB application.

I want to identify which user is currently using my application on their machine (say get their login name).

If that user is not a member of a particular user group, I will disable features (eg buttons) on the application.

Do you have any suggestions or code on how to do this?

Any help much appreciated.
0
Comment
Question by:robert_m78
6 Comments
 
LVL 10

Expert Comment

by:DSPoole
ID: 6977959
You can set a DOS variable during login - and capture that with the ActiveX control - alternatively, the ActiveX controls provided by Novell should have documentation on developer.novell.com on how to access the NetWare/Novell variables used.

You will have to use the Novell-supplied NetWare client for Windows and not the Microsoft Client for NetWare Networks.
0
 

Expert Comment

by:VTP
ID: 6980353
Can you use SYS(0) -" SYS(0) returns the machine name and user name."?

I get my logged in user's name with gsUser = UPPER( RIGHT( SYS(0), LEN(SYS(0)) - (AT('#',SYS(0))+1) ) )
0
 
LVL 4

Expert Comment

by:Zombite
ID: 7038008

I have code in msaccess which does a function izemember(username,group) which allows you to check if login name is a member of a group - Depends on what you want.

Has some setup functions that need to run first to get tree and object info...

Might be good for you.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 4

Accepted Solution

by:
Zombite earned 100 total points
ID: 7040798
This pops the current users group membership into an array
I am assuming you have all the definitions and netware functions defined. Izemember then checks the array for groups. If not let me know.


Public Function NDSgetinfo()

Dim objName As String
Dim defContext As String
Dim iterHandle As Long
Dim flags As Long
Dim attrCount As Long
Dim inBuf As Long
Dim outBuf As Long
Dim syntaxID As Long
Dim i As Long
Dim j As Long
Dim contexthandle As Long
Dim byteName(128) As Byte
Dim retcode As Long
Dim iterread As Long
Dim context As Long
Dim myString As String
Dim Whoamistring As String * 256
Dim myByte(128) As Byte
Dim nameofattrib As String * 256
Dim attval(128) As Byte
Dim strattvalue As String
Dim Attribsize As Long
Dim byteAttName(256) As Byte
Dim Whoami As String, attrValCount As Long, membership(250) As String

' NWCallsInit
    retcode = NWCallsInit(0, 0)
    If retcode <> 0 Then
        MsgBox "NWcallsInit failed, E=" + retcode, vbCritical
       '
    End If
   
' We will use only one global DS context handle
    retcode = NWDSCreateContextHandle(contexthandle)
    If retcode <> 0 Then
        MsgBox "NWDSCreateContextHandle failed, E=" + retcode, vbCritical
       '
    End If

'Check to see if we are logged in

    retcode = NWIsDSAuthenticated()
             
              If retcode <> 1 Then
              MsgBox ("you are not logged in")
              End
              End If
   
' The good habit is to set default context to [Root]
'   If we don`t do it, all get/set  calls are relative
'   to the current context !
   
    myString = DS_ROOT_NAME + chr(0)
    Call StringToByteArray(myByte, myString)
    retcode = NWDSSetContext(contexthandle, DCK_NAME_CONTEXT, myByte(0))
   
'We would like to get 'typeless' results so we have to set
'   our context flags appropriately:
    retcode = NWDSGetContext(contexthandle, DCK_FLAGS, myByte(0))
    Call ByteArrayToLong(myByte, flags)
   flags = flags Or DCV_TYPELESS_NAMES
    Call LongToByteArray(flags, myByte)
    retcode = NWDSSetContext(contexthandle, DCK_FLAGS, myByte(0))
   
' Now we can try to get default DS tree name from our context
    retcode = NWDSGetContext(contexthandle, DCK_TREE_NAME, myByte(0))
    If retcode = 0 Then
        Call ByteArrayToString(myString, myByte)
'        Text1.value = ("Tree    =  " + myString + "   ")
    End If
   
' Here we want to get our DS user name (CN)
    retcode = NWDSWhoAmI(contexthandle, Whoamistring)
   
    If retcode <> 0 Then
        MsgBox ("whoami got Error code " + retcode)
    End If
   
' Do a double converstion from string to byte,then bye to string
' to get rid of excess characters in name

    Call StringToByteArray(myByte, Whoamistring)
    Call ByteArrayToString(myString, myByte)

'      Setting default context to [Root] is good
        defContext = DS_ROOT_NAME + chr(0)
        Call StringToByteArray(byteName, defContext)
        retcode = NWDSSetContext(contexthandle, DCK_NAME_CONTEXT, VarPtr(byteName(0)))
             
              iterHandle = NO_MORE_ITERATIONS
 
                   
    retcode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, inBuf)
    If retcode <> 0 Then
    MsgBox (" Alloc Buffer inbuf returned error   " & retcode)
    End If
                         
    retcode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, outBuf)
    If retcode <> 0 Then
    MsgBox (" Alloc Buffer outbuf returned error   " & retcode)
    End If
           
                       
    retcode = NWDSInitBuf(contexthandle, DSV_READ, inBuf)
    If retcode <> 0 Then
    MsgBox (" Init Buffer inbuf returned error   " & retcode)
    End If
           
   retcode = NWDSInitBuf(contexthandle, DSV_READ, outBuf)
   If retcode <> 0 Then
   MsgBox (" Init Buffer outbuf returned error   " & retcode)
   End If
                       
   'Lets stick Group Membership into the inbuf buffer
                       
   retcode = NWDSPutAttrName(contexthandle, inBuf, "Group Membership" + chr(0))
   If retcode <> 0 Then
   MsgBox (" Put Attrib Name 1 returned error   " & retcode)
   End If
             
    'Add leading . and trailing chr(0) to our user name
    objName = "." + myString + chr(0)
                     
    iterread = NO_MORE_ITERATIONS
                   
 'Covert our string into a byte array
 
    Call StringToByteArray(byteName, objName)
                                         
 'Read the attrib values etc from NDS
 
    retcode = NWDSRead(contexthandle, objName, DS_ATTRIBUTE_VALUES, False, inBuf, iterread, outBuf)
                           
   If retcode <> 0 Then
   MsgBox (" ERROR NDS Read  is   " & retcode)
   End If
                         
 'Get the count of attributes
 
  retcode = NWDSGetAttrCount(contexthandle, outBuf, attrCount)
                       
  If retcode <> 0 Then
  MsgBox (" ERROR NDS GetAttribRead  is   " & retcode)
  End If
       
 'Loop for as many attributes as we found ( always 1 with this code
 'but may change later
 
  For i = 0 To attrCount - 1
                     
 'Get the name of the attribute
 retcode = NWDSGetAttrName(contexthandle, outBuf, nameofattrib, attrValCount, syntaxID)
                           
 If retcode <> 0 Then
 MsgBox (" Get attrib Name  returned  " & retcode)
 End If
                   
 'Loop for the number of values in the attribute we are looking at
    'Add this to the public variable
    Membership_number = attrValCount - 1
   
    For j = 0 To attrValCount - 1
               
        'Get the value for the attribute
 
        retcode = NWDSGetAttrVal(contexthandle, outBuf, syntaxID, attval(0))
                     
        'Convert the attribute byte to a string
 
        Call ByteArrayToString(strattvalue, attval)
  '      Call StringToByteArray(attval, strattvalue)
   '     Call ByteArrayToString(strattvalue, attval)
   
    'we add it to the GROUP MEMEBERSHIP VARIABLE ARRAY we have AFTER REMOVING THE FULL
    'CONTEXT
        membership(j) = (left(strattvalue, (InStr(1, strattvalue, ".") - 1)))
        'add this to the public variable
        Membership_list(j) = (left(strattvalue, (InStr(1, strattvalue, ".") - 1)))
       
    Next j
Next i
   
'Clean up our NDS functions

    NWDSFreeBuf (outBuf)
    NWDSFreeBuf (inBuf)
    NWDSFreeContext (context)
             
End Function

Function izemember(group As String) As Boolean
    Dim temp1 As Integer
   
    izemember = False
     For temp1 = 0 To Membership_number
       If UCase(group) = UCase(Membership_list(temp1)) Then izemember = True
     Next temp1
   
End Function
0
 
LVL 4

Expert Comment

by:Zombite
ID: 7202052
Any more info required ?
0
 

Author Comment

by:robert_m78
ID: 7486605
Many thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now