我们有一个全名域名,例如long-domainname.com;此域名替换为别名short。可以使用 检索此别名netapi32.dll
,如下所示:
[DllImport("Netapi32.dll")]
static extern int NetApiBufferFree(IntPtr Buffer);
// Returns the domain name the computer is joined to, or "" if not joined.
public static string GetJoinedDomain()
{
int result = 0;
string domain = null;
IntPtr pDomain = IntPtr.Zero;
NetJoinStatus status = NetJoinStatus.NetSetupUnknownStatus;
try
{
result = NetGetJoinInformation(null, out pDomain, out status);
if (result == ErrorSuccess &&
status == NetJoinStatus.NetSetupDomainName)
{
domain = Marshal.PtrToStringAuto(pDomain);
}
}
finally
{
if (pDomain != IntPtr.Zero) NetApiBufferFree(pDomain);
}
if (domain == null) domain = "";
return domain;
}
此方法返回排序值。但是使用System.DirectoryServices.ActiveDirectory.Domain
该类及其Name
属性,我得到了 long-domainname.com值。在调试模式下搜索属性,我找不到任何短值字段或属性。System.DirectoryServices.ActiveDirectory.Domain
上课可以吗?或者可能有其他类的System.DirectoryServices
命名空间?如何在不导入外部 *.dll 的情况下获取短域名值?