Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
 internal static extern int DsGetDcSiteCoverage([MarshalAs(UnmanagedType.LPTStr)] string ServerName, out long EntryCount, out SafeDsSiteNameHandle SiteNames);
 internal static extern int DsGetSiteName(string server, out SafeDsSiteNameHandle siteName);