在.NET中,计算机的域名? [英] Machine's domain name in .NET?
问题描述
有一定有一个简单的方法来做到这一点,我可以不相信有没有。我已经通过网络扫描,发现一样,20种不同的方法来查找哪个域当前用户,但没有得到当前计算机的域(或工作组)。
There gotta be an easy way to do this, I can't believe there's none. I have scanned through net and found, like, 20 different methods to find in which domain current user is, but none to get domain (or workgroup) of current machine.
在非托管C ++,这是检索:
In unmanaged c++ this is retrieved by:
WKSTA_INFO_100 *buf;
NetWkstaGetInfo(NULL, 100, (LPBYTE*)buf);
domain_name = pBuf->wki100_langroup;
有人可以帮助我,如果有一种方式来获得在托管的C#相同的信息本身?
can someone help me, if there's a way to get same info in managed C# natively?
EDIT1:伙计们,请阅读问题。我不是在寻找的用户域名。
推荐答案
要在其上编程'的运行,就可以使用得到系统的当前域 System.DirectoryServices.ActiveDirectory.Domain 。
To get the current domain of the system on which your progam is running you can use System.DirectoryServices.ActiveDirectory.Domain.
Domain domain = Domain.GetComputerDomain();
Console.WriteLine( domain.Name );
这篇关于在.NET中,计算机的域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!