Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5996423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:06:04+00:00 2026-05-23T00:06:04+00:00

When working with the access rules returned by GetAccessRules(True, True, GetType(System.Security.Principal.NTAccount)) how can I

  • 0

When working with the access rules returned by

GetAccessRules(True, True, GetType(System.Security.Principal.NTAccount))

how can I tell if the NTAccount object referenced in each rule is a user account or a group?

Update:

I was able to solve this as follows. Note, the intent of this code is to return True if the NTAccount is a group, and False otherwise or if an error occurs during checking.

Is there a better way to do this?

Public Function IsGroup(ByVal account As NTAccount) as Boolean  
    Dim samAccountName as string = account.Value  
    Dim accountNameParts() As String = samAccountName.Split("\")  
    If accountNameParts.Count() = 2 Then  
        Dim principalContext As PrincipalContext  
        Try  
            principalContext = New PrincipalContext(ContextType.Domain, accountNameParts(0))  
        Catch  
            Try  
                principalContext = New PrincipalContext(ContextType.Machine, accountNameParts(0))  
            Catch  
                principalContext = Nothing  
            End Try  
        End Try  
        If Not principalContext Is Nothing Then  
            Dim principal As Principal  
            principal = principal.FindByIdentity(principalContext, _samAccountName)  
            If Not principal Is Nothing then   
                return TypeOf principal Is GroupPrincipal  
            End If  
        End If  
    End If  
    Return False  
End Function

Another update:

The above solution was okay for most server\account objects, but it fails for local group objects on the EMC Celerra NAS servers we have. I’m trying to use the NetUserGetInfo/NetLocalGroupGetInfo Win API calls to see if that will work, but I can’t get them to work properly. See NetUserGetInfo/NetLocalGroupGetInfo returning error 1722 for more details.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:06:04+00:00Added an answer on May 23, 2026 at 12:06 am

    The answer to this was indeed to use the Windows APIs (NetUserGetInfo and NetLocalGroupGetInfo).

    Class NetApi
        Private Declare Unicode Function NetUserGetInfo Lib "Netapi32.dll" ( _
             ByVal ServerName As String, _
             ByVal UserName As String, _
             ByVal level As Integer, _
             ByRef BufPtr As IntPtr) As Integer
    
        Private Declare Unicode Function NetLocalGroupGetInfo Lib "Netapi32.dll" ( _
             ByVal ServerName As String, _
             ByVal GroupName As String, _
             ByVal level As Integer, _
             ByRef BufPtr As IntPtr) As Integer
    
        Declare Unicode Function NetApiBufferFree Lib "netapi32.dll" _
        (ByRef buffer As IntPtr) As Long
    
        Public Shared Function PrincipalIsGroup(ByVal MachineName As String, ByVal AccountName As String) As String
            If String.IsNullOrEmpty(MachineName) Then
                Throw New ArgumentException("MachineName is Required")
            End If
            If String.IsNullOrEmpty(AccountName) Then
                Throw New ArgumentException("AccountName is Required")
            End If
            Dim returnValue As String = "NotFound"
            Dim bufPtr As IntPtr
            Dim lngReturn As Integer = NetLocalGroupGetInfo("\\" & MachineName, AccountName, 0, bufPtr)
            Call NetApiBufferFree(bufPtr)
            bufPtr = IntPtr.Zero
            If lngReturn = 0 Then
                returnValue = "True"
            Else
                lngReturn = NetUserGetInfo("\\" & MachineName, AccountName, 0, bufPtr)
                Call NetApiBufferFree(bufPtr)
                bufPtr = IntPtr.Zero
                If lngReturn = 0 Then
                    returnValue = "False"
                End If
            End If
            Return returnValue
        End Function
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an old Access database (yes, it's very ugly and I hate
I'm currently working in a piece of code where both logic and data access
I coded something using Date statement in Access VBA. It was working fine until
I've developed an application at working using MySQL 5, that uses Views to access
I'm trying to delete several working copy directories, but I get an Access Denied
In the application I'm working on porting to the web, we currently dynamically access
Hi I have been trying to access the validation rules of an associated model
Suddenly, local file access using jQuery's .getJSON is not working for me on Firefox
I had this almost working several hours ago, but I can't seem to get
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.