C# Platform Invoke ADUser Constructors parameterless

cook bada 1 Reputation point
2020-12-06T07:06:38.437+00:00

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;
Console.WriteLine(pi.Name);
Console.ReadKey();
}
}
}
namespace Microsoft.ActiveDirectory.Management
{
public class ADUser
{
public ADUser() { }
}
}
}

C#
C#
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.
10,312 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,621 Reputation points
    2020-12-07T02:33:40.653+00:00

    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