Link to home
Start Free TrialLog in
Avatar of Pirouz
Pirouz

asked on

Getting UserGroup on win98

Is there any way to get UserGroup of a user who has logged on in a windows 98?

We have some global groups in our domain, and I want to disable/enable menus depending on User's Group.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Avatar of anu1401
anu1401

this is to check who r all the users logged into that domain.. check it out!!!

Public Function GetLoggedOnUsers(ByVal ServerName As String) As Variant
   Dim p_lngRtn                        As Long
   Dim p_lngPtrBuffer                  As Long
   Dim p_lngPtrUserInfoBuf             As Long
   Dim p_lngEntriesRead                As Long
   Dim p_lngTotalEntries               As Long
   Dim p_lngResumeHwnd                 As Long
   Dim p_lngLoop                       As Long
   Dim p_lngLastLogon                  As Long
   Dim p_lngLastLogoff                 As Long
   Dim p_strUserName                   As String
   Dim p_abytServerName()              As Byte
   Dim p_abytUserName()                As Byte
   Dim p_atypUserInfo()                As USER_INFO_10_API
   Dim p_typUserInfo                   As USERINFO_2_API
   
   ' ------------------------------------------
   ' Initialize the variable(s)
   ' ------------------------------------------
   If ServerName = "" Then
      p_abytServerName = Chr$(0)
   Else
      p_abytServerName = "\\" & ServerName & Chr$(0)
   End If
   
   ' ------------------------------------------
   ' Make appropriate API call and check for error
   ' ------------------------------------------
   p_lngRtn = NetUserEnum(ServerName:=p_abytServerName(0), _
                          Level:=10, _
                          Filter:=0&, _
                          Buffer:=p_lngPtrBuffer, _
                          PrefMaxLen:=&H4000, _
                          EntriesRead:=p_lngEntriesRead, _
                          TotalEntries:=p_lngTotalEntries, _
                          ResumeHwnd:=p_lngResumeHwnd)
   If p_lngRtn <> 0 Then
      MsgBox "Had an error with NetUserEnum, " & CStr(p_lngRtn), _
             Buttons:=vbInformation, _
             Title:="GetLoggedOnUsers"
      Exit Function
   End If

   ' ------------------------------------------
   ' Exit if no entries found
   ' ------------------------------------------
   If p_lngEntriesRead < 1 Then
      Exit Function
   End If
   
   ' ------------------------------------------
   ' Redim the type array to hold this info
   ' ------------------------------------------
   ReDim p_atypUserInfo(0 To p_lngEntriesRead - 1)
         
   ' ------------------------------------------
   ' Copy the pointer to the buffer into the
   '     type array
   ' ------------------------------------------
   CopyMem p_atypUserInfo(0), _
           ByVal p_lngPtrBuffer, _
           Len(p_atypUserInfo(0)) * p_lngEntriesRead

   ' ------------------------------------------
   ' Fill-in the info needed to call the
   '     Add() method
   ' NOTE: We will always have +1 open pipe,
   '       since in making this call we create
   '       a pipe, "\PIPE\srvsvc"
   ' ------------------------------------------
   For p_lngLoop = 0 To p_lngEntriesRead - 1
      p_strUserName = PointerToUnicodeStr(p_atypUserInfo(p_lngLoop).Name)
     
      p_abytUserName = p_strUserName & Chr(0)
     
      p_lngRtn = NetUserGetInfo(ServerName:=p_abytServerName(0), _
                                Username:=p_abytUserName(0), _
                                Level:=2, _
                                Buffer:=p_lngPtrUserInfoBuf)
      If p_lngRtn <> 0 Then
         MsgBox "Had an error with NetUserGetInfo, " & CStr(p_lngRtn), _
                Buttons:=vbInformation, _
                Title:="GetLoggedOnUsers"
         Exit Function
      End If
     
      CopyMem p_typUserInfo, _
              ByVal p_lngPtrUserInfoBuf, _
              Len(p_typUserInfo)
     
      p_lngLastLogon = p_typUserInfo.usri2_last_logon
      p_lngLastLogoff = p_typUserInfo.usri2_last_logoff
     
      If p_lngLastLogoff = 0 And p_lngLastLogon = 0 Then
         MsgBox " **** " & p_strUserName & " has NEVER logged in"
      ElseIf (p_lngLastLogoff < p_lngLastLogon) Then
         MsgBox p_strUserName & " is still logged in -- " & p_lngLastLogoff, p_lngLastLogon
      Else
         MsgBox " **** " & p_strUserName & " is NOT logged in"
      End If
     
      If p_lngPtrUserInfoBuf <> 0 Then
         NetApiBufferFree p_lngPtrUserInfoBuf
      End If
     
   Next p_lngLoop
   
   ' ------------------------------------------
   ' Clean-up the buffer
   ' ------------------------------------------
   If p_lngPtrBuffer <> 0 Then
      NetApiBufferFree p_lngPtrBuffer
   End If

End Function
Avatar of Pirouz

ASKER

I dont know what these types are:

USER_INFO_10
USER_INFO_2

Also, my application must run on a windows 98 OS, and the function must work on it, I dont want a list of all users.

I got username, with "GetUserName" function, now I want to get UserGroup as well.
Avatar of Pirouz

ASKER

angellll,

it seems that you are a great expert, why didnt you answer to my question?
>>it seems that you are a great expert...
thanks for the compliment :-)

>>...why didnt you answer to my question?
obviously because I don't know the answer :-(

CHeers
Avatar of Pirouz

ASKER

so, there is no solution:(

I have to use my own old way, making a stored procedure in sql server for each group, and permit using it for that group, then calling it in vb, and check for error,  if there is no error, the logged on user, is a member of that group.

but I know that is not a advanced method!
Pirouz, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

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