[VB] know a user, how to get the user's permissions value?

That is, how to judge whether the user is the administrator or the ordinary jurisdiction?
That's it, thank you.

Started by Daphne at December 04, 2016 - 9:43 PM

? Worried to death

Posted by Daphne at December 14, 2016 - 10:32 PM

See the user group
Option Explicit

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Declare Function lstrcpyW Lib "kernel32.dll" (ByVal lpString1 As Long, ByVal lpString2 As Long) As Long
Private Declare Function lstrlenW Lib "kernel32.dll" (ByVal lpString As Long) As Long
Private Declare Function NetApiBufferFree Lib "netapi32.dll" (ByVal pBuffer As Long) As Long
Private Declare Function NetUserGetLocalGroups Lib "netapi32.dll" (ByVal lpServerName As Long, ByVal lpUserName As Long, ByVal Level As Long, ByVal Flags As Long, ByRef bufptr As Long, ByVal prefmaxlen As Long, ByRef entriesread As Long, ByRef totalentries As Long) As Long

Private Const NERR_Success As Long = 0&
Private Const ERROR_ACCESS_DENIED As Long = 5&
Private Const NERR_BASE As Long = 2100
Private Const NERR_InvalidComputer As Long = (NERR_BASE + 251)
Private Const NERR_UserNotFound As Long = (NERR_BASE + 121)
Private Const LG_INCLUDE_INDIRECT As Long = (&H1)

Sub Main()
Dim lpBuffer As Long
Dim lRead As Long
Dim lTotal As Long
Dim lRet As Long
Dim lpGroups() As Long
Dim i As Long

lRet = NetUserGetLocalGroups(StrPtr("\\servername"), StrPtr("username"), 0, 0&, lpBuffer, 1024, lRead, lTotal)
If lRet = NERR_Success Then
ReDim lpGroups(0 To lRead - 1) As Long
CopyMemory lpGroups(0), ByVal lpBuffer, lRead * 4

For i = 0 To lRead - 1
Debug.Print GetStringFromPtr(lpGroups(i))
Next i
End If

If lpBuffer Then
Call NetApiBufferFree(lpBuffer)
End If
End Sub

Function GetStringFromPtr(ByVal lpString As Long) As String
Dim s As String
s = Space(lstrlenW(lpString))
lstrcpyW StrPtr(s), lpString

GetStringFromPtr = s
End Function

Posted by Clyde at December 15, 2016 - 11:18 PM

Top, learning about

Posted by Bert at December 29, 2016 - 11:48 PM