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

  • Home
  • SEARCH
  • 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 1063149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:44:27+00:00 2026-05-16T18:44:27+00:00

I have the following code (VB.NET) which is designed to determine if a given

  • 0

I have the following code (VB.NET) which is designed to determine if a given account name refers to a local group or a user account. This will only be called for accounts/groups on a machine, not a domain.

Module netapi
    Private Declare 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 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 Function GetPrincipalType(ByVal MachineName As String, ByVal AccountName As String) As String
        Dim bufPtr As IntPtr
        Dim lngReturn As Integer = NetUserGetInfo("\\" & MachineName, AccountName, 0, bufPtr)
        Console.WriteLine("NetUserGetInfo return value = " & lngReturn)
        Call NetApiBufferFree(bufPtr)
        bufPtr = IntPtr.Zero
        If lngReturn = 0 Then
            Return "User"
        End If
        lngReturn = NetLocalGroupGetInfo("\\" & MachineName, AccountName, 0, bufPtr)
        Console.WriteLine("NetLocalGroupGetInfo return value = " & lngReturn)
        Call NetApiBufferFree(bufPtr)
        bufPtr = IntPtr.Zero
        If lngReturn = 0 Then
            Return "Group"
        End If
        Return "NotFound"
    End Function
End Module

My problem is that the NetUserGetInfo/NetLocalGroupGetInfo calls always return error code 1722 (RPC Server unavailable). I’ve tried using the local machine name and the name of remote Windows servers, on which I have admin rights, with the same result.

If I replace "\\" & MachineName with Nothing then I get error 2221/2220 (User/Group not found) regardless of whether or not the account/group referenced by AccountName actually exists.

Please help. What am I doing wrong?

Update: Not sure if this helps, but I’ve tried running the above on both Win 7 and Win XP SP3. My compilation is targetting the .NET 4.0 Client framework.

  • 1 1 Answer
  • 1 View
  • 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-16T18:44:28+00:00Added an answer on May 16, 2026 at 6:44 pm

    NetUserGetInfo and NetLocalGroupGetInfo both expect Unicode (wide) string parameters. Can you Declare Unicode these methods and confirm whether the problem persists?

    Also see http://www.xtremedotnettalk.com/showthread.php?t=69609

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which is created with a datalist control: http://jsfiddle.net/vmE2E/1/ But
I have somebody elses code (C# ASP.Net) which contains the following query: string query
I have the following code: http://jsfiddle.net/SPWWx/ I'm completely new to javascript, this is my
I have the following code: Redirect /email http://email.secureserver.net Which doesn't seem to be working.
I have the following code: http://jsfiddle.net/EMX4Q/ Which is very simple, when you mouseover the
I have the following code which posts file to ASP.net page: using (var Client
I have just come across the following code (.NET 3.5), which doesn't look like
I have the following code which pulls json data from an ASP.NET page and
I have following asp.net code but it gives error when I change dropdown selected
I have following code that I am compiling in a .NET 4.0 project namespace

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.