A shorter solution, just check the registry:
const string basename = "HKEY_LOCAL_MACHINE\\";
const string keyname = "SYSTEM\\CurrentControlSet\\Control\\ProductOptions";
string result = (string) Registry.GetValue(basename + keyname, "ProductType", "WinNT");
If the result is " WinNT ", this is the client machine. If it is ServerNT , the server and LanmanNT are domain controllers.
: https://technet.microsoft.com/en-us/library/cc782360%28v=ws.10%29.aspx