2

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.

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • For clarification, do you want the name of the computer *your code is running on*? Or the name of any arbitrary computer whose alternate Id you specify (such as a NetBIOS name, DNS name, etc) ? It makes a difference. – WhozCraig Nov 10 '12 at 22:37
  • I need it for computer that my code is running on. Thanks! – c00000fd Nov 10 '12 at 22:44

2 Answers2

7

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);
WhozCraig
  • 65,258
  • 11
  • 75
  • 141
  • 2
    Thanks. This is exactly what I needed. BTW, for those who want to get the DN for a user, replace it with GetUserNameEx(). – c00000fd Nov 10 '12 at 23:12
  • @user843732 Glad it helped. Its a really boring function when you're NOT domain-rooted (every option returns FALSE), but I can see it *very* helpful when you *are* on a domain. – WhozCraig Nov 10 '12 at 23:15
1

You probably want the GetComputerNameEx function documented on http://msdn.microsoft.com/en-us/library/windows/desktop/ms724301%28v=vs.85%29.aspx

Marcus Ilgner
  • 6,935
  • 2
  • 30
  • 44