【vb】知道某个用户,怎么获取这个用户的权限值呢?
即,如何判断这个用户是管理员还是普通权限呢?
仅此而已,谢谢。
vb 管理员,权限,用户
[解决办法]
看用户组
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