Search code examples
c++winapiactive-directorydomaincontrollerdistinguishedname

How to get a computer's Distinguished Name (DN) with C++


I can't seem to find a way to get a DN of a workstation (computer) with C++ and WinAPIs. Any ideas how to do this?

PS. The workstation is connected to a domain controller.

PS2. I need the DN of a computer and not the logged on user.


Solution

  • If you want the name of the computer on which your code is running, and it is participating in a domain, then you can use GetComputerObjectName:

    #include <security.h>
    #include <secext.h>
    
    TCHAR szDN[1024];
    ULONG ulSize = sizeof(szDN)/sizeof(szDN[0]);
    BOOL res = GetComputerObjectName(NameFullyQualifiedDN, szDN, &ulSize);