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 8161639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:32:29+00:00 2026-06-06T18:32:29+00:00

I want to use http://msdn.microsoft.com/en-us/library/aa370654%28VS.85%29.aspx in my code. But for some reason I cannot

  • 0

I want to use http://msdn.microsoft.com/en-us/library/aa370654%28VS.85%29.aspx in my code. But for some reason I cannot find what namespace to use for it. Three that I thought would work are

using System.DirectoryServices.AccountManagement;
using System.Runtime.InteropServices;
using System.DirectoryServices;

But none of these work. All of the examples of using NetUserGetInfo I can find are in C++, rather than C#. That makes me think that maybe I cannot use it in C#. Can I? And if so, what namespace I should use to have access to the NetUserGetInfo function? Any help is appreciated.

  • 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-06-06T18:32:31+00:00Added an answer on June 6, 2026 at 6:32 pm

    What namespace are you looking for? Namespaces are .NET specific notions. The NetUserGetInfo is a Win32 unmanaged function. If you want to invoke it from managed .NET code you need to write a managed wrapper and call it through P/Invoke.

    Here’s a useful site in this case which illustrates the following managed wrapper:

    [DllImport("Netapi32.dll", CharSet=CharSet.Unicode, ExactSpelling=true)]
    private extern static int NetUserGetInfo(
        [MarshalAs(UnmanagedType.LPWStr)] string ServerName,
        [MarshalAs(UnmanagedType.LPWStr)] string UserName, 
        int level, 
        out IntPtr BufPtr
    );
    

    A user defined structure:

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct USER_INFO_10
    {
        [MarshalAs(UnmanagedType.LPWStr)]
        public string usri10_name;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string usri10_comment;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string usri10_usr_comment;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string usri10_full_name;
    }
    

    and a sample invocation:

    public bool AccountGetFullName(string MachineName, string AccountName, ref string FullName) 
    {
        if (MachineName.Length == 0 ) 
        {
            throw new ArgumentException("Machine Name is required");
        }
        if (AccountName.Length == 0 ) 
        {
            throw new ArgumentException("Account Name is required");
        }
        try 
        {
            // Create an new instance of the USER_INFO_1 struct
            USER_INFO_10 objUserInfo10 = new USER_INFO_10();
            IntPtr bufPtr; // because it's an OUT, we don't need to Alloc
            int lngReturn = NetUserGetInfo(MachineName, AccountName, 10, out bufPtr ) ;
            if (lngReturn == 0) 
            {
                objUserInfo10 = (USER_INFO_10) Marshal.PtrToStructure(bufPtr, typeof(USER_INFO_10) );
                FullName = objUserInfo10.usri10_full_name;
            }
            NetApiBufferFree( bufPtr );
            bufPtr = IntPtr.Zero;
            if (lngReturn == 0 ) 
            {
                return true;
            }
            else 
            {
                //throw new System.ApplicationException("Could not get user's Full Name.");
                return false;
            }
        } 
        catch (Exception exp)
        {
            Debug.WriteLine("AccountGetFullName: " + exp.Message);
            return false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to use the Caching Handler: http://msdn.microsoft.com/en-us/library/ff648868.aspx I may want to use some
I want to draw a String on some shapes following the examples in http://msdn.microsoft.com/en-us/library/aa327572%28v=vs.71%29.aspx
It is said here http://msdn.microsoft.com/en-us/library/fa13yay7%28v=VS.90%29.aspx (see also http://msdn.microsoft.com/en-us/library/s4wcexbc%28VS.90%29.aspx ) Use this option if you
I want to use Activator.CreateInstance(string assemblyName,string typName) ( http://msdn.microsoft.com/en-us/library/d133hta4%28v=VS.100%29.aspx ) in my Windows Phone
I want to use wcf performance counters per operation , like here: http://msdn.microsoft.com/en-us/library/ms731052(v=vs.90).aspx how
I've modified Producer/Consumer example http://msdn.microsoft.com/en-us/library/yy12yx1f(v=vs.80).aspx . I don't want Consumer to process queue on
The code sample How to: Define Event Accessor Methods at http://msdn.microsoft.com/en-us/library/dw1dtw0d.aspx appears to mutate
I am building an ajax form using the MVC Ajax Helpers: http://msdn.microsoft.com/en-us/library/dd505013.aspx The code
everyone. I have BMP specification from MS ( http://msdn.microsoft.com/en-us/library/dd183383.aspx ) and I want to
I want to use oscpack ( http://code.google.com/p/oscpack/ ) as a static library for my

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.