public static StringCollection GetDcSiteCoverage(string fqdn) { if (string.IsNullOrEmpty(fqdn)) { throw new ArgumentNullException("fqdn"); } StringCollection stringCollection = new StringCollection(); SafeDsSiteNameHandle safeDsSiteNameHandle = null; long num = 0L; try { int num2 = NativeMethods.DsGetDcSiteCoverage(fqdn, out num, out safeDsSiteNameHandle); if (num2 != 0) { throw new CannotGetSiteInfoException(DirectoryStrings.CannotGetSiteInfo(num2.ToString("X"))); } int num3 = 0; while ((long)num3 < num) { stringCollection.Add(Marshal.PtrToStringAuto(Marshal.ReadIntPtr(safeDsSiteNameHandle.DangerousGetHandle(), num3 * IntPtr.Size))); num3++; } } finally { if (safeDsSiteNameHandle != null) { safeDsSiteNameHandle.Dispose(); } } return(stringCollection); }
public string GetSiteNameHookable(bool throwOnErrorNoSite = false) { SafeDsSiteNameHandle safeDsSiteNameHandle = null; string result; try { int num = NativeMethods.DsGetSiteName(null, out safeDsSiteNameHandle); if (num == NativeMethods.ERROR_NO_SITE) { if (throwOnErrorNoSite) { throw new CannotGetSiteInfoException(DirectoryStrings.CannotGetUsefulSiteInfo) { ErrorCode = num }; } result = null; } else { if (num != 0) { throw new CannotGetSiteInfoException(DirectoryStrings.CannotGetSiteInfo(num.ToString("X"))) { ErrorCode = num }; } result = Marshal.PtrToStringUni(safeDsSiteNameHandle.DangerousGetHandle()); } } finally { if (safeDsSiteNameHandle != null) { safeDsSiteNameHandle.Dispose(); } } return(result); }