C# Platform Invoke ADUser Constructors parameterless

cook bada 1 Reputation point

Hi Developers !

I'am a newer of C#,once i want to practice how to Invoke Unmanaged code
And i got the Assembly:Microsoft.ActiveDirectory.Management.dll,to practice how to use
ADUser Constructors to create an abject whose properties are similar to a ADUser classs in my view.
Then print all properties and methods of the abject
Although i have been read about PlatformInvoke topic in "C# advancing programming" but i also can not perform my Task

Why not i come to DirectoryEntry class to get the abject ,because this method need a path parameter that is related to Active Directory
And i want this code Active Directory independence and also without customing a class ,can it be realized
Anyone can help with some suggestions,below is my code:

using System;
using System.Runtime.InteropServices;
using Microsoft.ActiveDirectory.Management;
using System.Reflection;

namespace Test
{class Program
static void Main(string[] args)
var ADAccount = new ADUser();
Type t = ADAccount.GetType();
foreach (PropertyInfo pi in t.GetProperties())
string name = pi.Name;
namespace Microsoft.ActiveDirectory.Management
public class ADUser
public ADUser() { }

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,015 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,541 Reputation points

    Hi cookbada-7182,
    You can try to use ActiveDirectorySchema Class to query for the user class, and then call GetAllProperties method.
    oldovets has provided a simple code example in this thread you can refer to.
    Besides, you can also try the powershell cmdlet.
    Here is a related thread.
    Best Regards,
    Daniel Zhang

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments