我们有一个完整的域名,例如长域名.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;
}
该方法返回sort价值。但使用System.DirectoryServices.ActiveDirectory.Domain
类及其Name
财产,我得到长域名.com价值。在Debug模式下搜索属性,没有找到short值字段或属性。是否可以与System.DirectoryServices.ActiveDirectory.Domain
班级?或者可能是其他一些类别的System.DirectoryServices
命名空间?如何获得short域名值不导入外部*.dll?
private string GetNetbiosDomainName(string dnsDomainName)
{
string netbiosDomainName = string.Empty;
DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");
string configurationNamingContext = rootDSE.Properties["configurationNamingContext"][0].ToString();
DirectoryEntry searchRoot = new DirectoryEntry("LDAP://cn=Partitions," + configurationNamingContext);
DirectorySearcher searcher = new DirectorySearcher(searchRoot);
searcher.SearchScope = SearchScope.OneLevel;
searcher.PropertiesToLoad.Add("netbiosname");
searcher.Filter = string.Format("(&(objectcategory=Crossref)(dnsRoot={0})(netBIOSName=*))", dnsDomainName);
SearchResult result = searcher.FindOne();
if (result != null)
{
netbiosDomainName = result.Properties["netbiosname"][0].ToString();
}
return netbiosDomainName;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)