Solved

Getting users login name

Posted on 2002-04-29
6
806 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was initially published on Monitis Blog, you can read it here . When it comes to deciding which approach to website performance monitoring is best for your business, unfortunately, like so many options in life . . . it depends. In t…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

696 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