[windows] How do I find out which computer is the domain controller in Windows programmatically?

Run gpresult at a Windows command prompt. You'll get an abundance of information about the current domain, current user, user & computer security groups, group policy names, Active Directory Distinguished Name, and so on.