tags:

views:

1376

answers:

5

Hi,

In my application I need to know if the computer is the primary domain controller of a domain, so I need to know the domain of the computer to call NetGetDCName function.

Thanks.

EDIT: The problem is related with the DCOM authentication so I need to know the domain to use the DOMAIN\USERNAME in case of a PDC or COMPUTER\USERNAME if I need to use the local authentication database of the computer.

+3  A: 

I would consider using NetWkstaGetInfo() and pass the local computer name is that first parameter.

#include <Lmwksta.h>
#include <StrSafe.h>

WCHAR domain_name[256];
WKSTA_INFO_100 info = {0};
if (NERR_Success == NetWkstaGetInfo(L"THIS-COMPUTER", 100, &info) && 
    SUCCEEDED(StringCchCopy(domain_name, ARRAYSIZE(domain_name), info.wki100_langroup))) {
    // use domain_name here...
}
jeffamaphone
I'm going to try this.
xgoan
+2  A: 

You can use the NetWkstaGetInfo Function do this.

If you pass in null for the computer name it returns info about the local computer.

It will return a WKSTA_INFO_100 instance, which includes the domain name.

Scott Wisniewski
+2  A: 

If you just want to know if the machine the code is running is the primary domain controller I think your best option is NetServerGetInfo. If you pass 101 as the level parameter it returns an SERVER_INFO_101 structure. Then look for its sv101_type member:

sv101_type

The type of software the computer is running. This member can be one of the following values.

(...)

SV_TYPE_DOMAIN_CTRL: A primary domain controller.

Romulo A. Ceccon
I need to know if the computer is PDC and the name of the domain. Thanks.
xgoan
A: 

Finally I have used this code. It works in local machine, executed remotely nStatus gives a ACCESS_DENIED error.

NET_API_STATUS nStatus;
TOleString oleServerName=strServerName.c_str();
DWORD dwLevel=101;
LPSERVER_INFO_101 pBufServer=NULL;
LPWKSTA_INFO_100 pBufWksta = NULL;

nStatus=NetServerGetInfo(oleServerName, dwLevel,
 (LPBYTE*)&pBufServer);
if(nStatus==NERR_Success &&
 (pBufServer->sv101_type & SV_TYPE_DOMAIN_CTRL))
{
 dwLevel=100;
 nStatus=NetWkstaGetInfo(oleServerName, 100,
  (LPBYTE*)&pBufWksta);

 if(nStatus==NERR_Success)
 {
  AnsiString strDomain(pBufWksta->wki100_langroup);

  m_pgServerConnection->SetDomain(strDomain);
 }
}

Thanks to all :)

xgoan
A: 

You don't need all this code (wrong): use AD apis (network FAQ, Google groups, Win32)