Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the domain name of a computer from Windows API

Tags:

c++

winapi

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.

like image 749
Jesus Fernandez Avatar asked Nov 27 '22 10:11

Jesus Fernandez


1 Answers

The NetWkstaGetInfo() function returns either the domain name or the workgroup of the computer, and is therefore not a reliable way to determine if the computer is a member of a domain.

The GetComputerNameEx() function will help, used with the ComputerNameDnsDomain parameter, as shown below. This will return an empty string if the computer is in a workgroup, or the DNS name of the domain:

DWORD bufSize = MAX_PATH;
TCHAR domainNameBuf[ MAX_PATH ];

GetComputerNameEx( ComputerNameDnsDomain, domainNameBuf, &bufSize );
like image 149
chrfrenning Avatar answered Dec 08 '22 06:12

chrfrenning