Results 1 to 8 of 8

Thread: User Privaleges ...

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Sure I asked this one before

    I know how to get a username / log on, but is there any way to tell if a user has admin / install rights on a PC please?

    Thanks All !

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    I have a sample for this somewhere Alex, I had to reformat my machine yesterday, so it may take me a wahile to find - but i'm digging as I write! bear with me...
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Yey!

    Don't think I got an answer last time so didn't think it was possible.

    No real rush, post when you're ready & thanks !

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    here ya go!

    http://www.vbadmincode.btinternet.co.uk/

    look for the netuser sample, I'm sure you can butcher the code here to just rip out the priviledge info bits (if ya need anything else just lemme know) I need this code too for some install packages I'm doing, and im going to rip those bits out at some point today, so If ya wanna wait for mine i'll post em later on...
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  5. #5

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Cheers Crispin, I'll take a look !

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  6. #6
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Here you go Alex, (I got most of this from ALLAPI.NET - but butchered a little of it) - paste it into a form...

    Code:
    Const NERR_Success = 0
    Const CP_ACP = 0
    Private Type USER_INFO_3
        usri3_name As Long
        usri3_password As Long
        usri3_password_age As Long
        usri3_priv As Long
        usri3_home_dir As Long
        usri3_comment As Long
        usri3_flags As Long
        usri3_script_path As Long
        usri3_auth_flags As Long
        usri3_full_name As Long
        usri3_usr_comment As Long
        usri3_parms As Long
        usri3_workstations As Long
        usri3_last_logon As Long
        usri3_last_logoff As Long
        usri3_acct_expires As Long
        usri3_max_storage As Long
        usri3_units_per_week As Long
        usri3_logon_hours As Byte
        usri3_bad_pw_count As Long
        usri3_num_logons As Long
        usri3_logon_server As String
        usri3_country_code As Long
        usri3_code_page As Long
        usri3_user_id As Long
        usri3_primary_group_id As Long
        usri3_profile As Long
        usri3_home_dir_drive As Long
        usri3_password_expired As Long
    End Type
    
    Private Const USER_PRIV_MASK = 3
    Private Const USER_PRIV_GUEST = 0
    Private Const USER_PRIV_USER = 1
    Private Const USER_PRIV_ADMIN = 2
    
    Private Declare Function NetUserGetInfo Lib "netapi32" (ByVal servername As String, ByVal username As String, ByVal level As Long, bufptr As Long) As Long
    Private Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As Long) As Long
    Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
    Private Declare Function lstrlenW Lib "kernel32" (lpString As Any) As Long
    Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal codepage As Long, ByVal dwFlags As Long, lpWideCharStr As Any, ByVal cchWideChar As Long, lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long
    ' Returns an ANSI string from a pointer to a Unicode string.
    Public Function GetStrFromPtrW(lpszW As Long) As String
        Dim sRtn As String
        sRtn = String$(lstrlenW(ByVal lpszW) * 2, 0)   ' 2 bytes/char
        ' WideCharToMultiByte also returns Unicode string length
        Call WideCharToMultiByte(CP_ACP, 0, ByVal lpszW, -1, ByVal sRtn, Len(sRtn), 0, 0)
        GetStrFromPtrW = GetStrFromBufferA(sRtn)
    End Function
    ' Returns the string before first null char encountered (if any) from an ANSII string.
    Public Function GetStrFromBufferA(sz As String) As String
        If InStr(sz, vbNullChar) Then
            GetStrFromBufferA = Left$(sz, InStr(sz, vbNullChar) - 1)
        Else
            ' If sz had no null char, the Left$ function
            ' above would return a zero length string ("").
            GetStrFromBufferA = sz
        End If
    End Function
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        ' -> Based on a KB article
        Dim lpBuf As Long
        Dim ui3 As USER_INFO_3
        ' replace "Administrator" with a valid NT username
        If (NetUserGetInfo("", StrConv("Administrator", vbUnicode), 3, lpBuf) = NERR_Success) Then
            Call MoveMemory(ui3, ByVal lpBuf, Len(ui3))
            If ui3.usri3_priv = USER_PRIV_ADMIN Then
                MsgBox "User Has Administrator Rights"
            End If
            Call NetApiBufferFree(ByVal lpBuf)
        End If
    End Sub
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  7. #7

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    That's fantastic, cheers crispin !

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  8. #8
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    pleasure. (specially since I seem to have lost about 900 posts on you in the last 3 or 4 months and i'm desperately trying to get mine up to a respectable level damnit!!!! - so if you've got any more scary ones like that then bring em on!!!)

    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width