tags:

views:

83

answers:

2

Some systems don't have a domain name configured or they might have something in the form of domain.local; yet they are located within a domain.

Is there a way to get the domain these system belong to?

I already tried using the classic APIs:

NetWkstaGetInfo() DnsQueryConfig()

and many others...

Code is appreciated.

A: 

getdomainname()

Sorry just noticed the windows tag, see list of network functions

Martin Beckett
all is well, except that all the network API are based on the fact that you configured a domain on the computer. what if you didn't? how can I get the domain the computer is connected currently?
wonderer
Sorry don't do much windows sysadmin stuff, that's why I posted the link to the entire list of functions rather than pick one.
Martin Beckett
+2  A: 

Try GetComputerNameEx()

GetComputerNameEx(ComputerNameDnsDomain, pszBuffer, &dwLength)
gwell
already tried that all all its brothers...
wonderer
Please see the comment on mgb's answer
wonderer
Are you after the DNS domain configured via DHCP?
gwell
I think so. I mean, think about it this way. you have a brand new computer that you just connected to the network. You received your IP and you can connect to the internet but you are NOT formally part of the domain. You will not find the "somedomain.com" anywhere on the usual places (registry or otherwise).
wonderer
So, the domain does not appear in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters ? You might try DhcpRequestParams().
gwell
thanks, but how is that different from the other APIs? can you give me a sample snippet that can provide the DNS name?
wonderer