internal static IEnumerable <string> EnumerateDfsRootCore(string host, bool continueOnException)
        {
            if (!Filesystem.NativeMethods.IsAtLeastWindowsVista)
            {
                throw new PlatformNotSupportedException(new Win32Exception((int)Win32Errors.ERROR_OLD_WIN_VERSION).Message);
            }


            return(EnumerateNetworkObjectCore(new FunctionData(), (NativeMethods.DFS_INFO_300 structure, SafeGlobalMemoryBufferHandle buffer) => new DfsInfo {
                EntryPath = structure.DfsName
            },

                                              (FunctionData functionData, out SafeGlobalMemoryBufferHandle buffer, int prefMaxLen, out uint entriesRead, out uint totalEntries, out uint resumeHandle) =>
            {
                totalEntries = 0;

                // When host == null, the local computer is used.
                // However, the resulting OpenResourceInfo.Host property will be empty.
                // So, explicitly state Environment.MachineName to prevent this.
                // Furthermore, the UNC prefix: \\ is not required and always removed.
                var stripUnc = !Utils.IsNullOrWhiteSpace(host) ? Path.GetRegularPathCore(host, GetFullPathOptions.CheckInvalidPathChars, false).Replace(Path.UncPrefix, string.Empty) : Environment.MachineName;

                return NativeMethods.NetDfsEnum(stripUnc, 300, prefMaxLen, out buffer, out entriesRead, out resumeHandle);
            }, continueOnException).Select(dfs => dfs.EntryPath));
        }
        private static IEnumerable <string> EnumerateDomainDfsRootCore(string domain, bool continueOnException)
        {
            if (!Filesystem.NativeMethods.IsAtLeastWindowsVista)
            {
                throw new PlatformNotSupportedException(Resources.Requires_Windows_Vista_Or_Higher);
            }

            return(EnumerateNetworkObjectCore(new FunctionData(), (NativeMethods.DFS_INFO_200 structure, SafeGlobalMemoryBufferHandle buffer) =>

                                              new DfsInfo {
                EntryPath = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}{3}", Path.UncPrefix, NativeMethods.ComputerDomain, Path.DirectorySeparatorChar, structure.FtDfsName)
            },

                                              (FunctionData functionData, out SafeGlobalMemoryBufferHandle buffer, int prefMaxLen, out uint entriesRead, out uint totalEntries, out uint resumeHandle) =>
            {
                totalEntries = 0;

                // When host == null, the local computer is used.
                // However, the resulting OpenResourceInfo.Host property will be empty.
                // So, explicitly state Environment.MachineName to prevent this.
                // Furthermore, the UNC prefix: \\ is not required and always removed.
                string stripUnc = Utils.IsNullOrWhiteSpace(domain) ? NativeMethods.ComputerDomain : Path.GetRegularPathCore(domain, GetFullPathOptions.CheckInvalidPathChars).Replace(Path.UncPrefix, string.Empty);

                return NativeMethods.NetDfsEnum(stripUnc, 200, prefMaxLen, out buffer, out entriesRead, out resumeHandle);
            }, continueOnException).Select(dfs => dfs.EntryPath));
        }
Beispiel #3
0
        public static IEnumerable <DfsInfo> EnumerateDfsLinks(string dfsName)
        {
            if (!Filesystem.NativeMethods.IsAtLeastWindowsVista)
            {
                throw new PlatformNotSupportedException(new Win32Exception((int)Win32Errors.ERROR_OLD_WIN_VERSION).Message);
            }


            if (Utils.IsNullOrWhiteSpace(dfsName))
            {
                throw new ArgumentNullException("dfsName");
            }


            var fd = new FunctionData();

            return(EnumerateNetworkObjectCore(fd, (NativeMethods.DFS_INFO_9 structure, SafeGlobalMemoryBufferHandle buffer) => new DfsInfo(structure),

                                              (FunctionData functionData, out SafeGlobalMemoryBufferHandle buffer, int prefMaxLen, out uint entriesRead, out uint totalEntries, out uint resumeHandle1) =>
            {
                totalEntries = 0;

                return NativeMethods.NetDfsEnum(dfsName, 9, prefMaxLen, out buffer, out entriesRead, out resumeHandle1);
            }, false));
        }
        private static IEnumerable <string> EnumerateDfsRootInternal(string host, bool continueOnException)
        {
            if (!Filesystem.NativeMethods.IsAtLeastWindowsVista)
            {
                throw new PlatformNotSupportedException(Resources.RequiresWindowsVistaOrHigher);
            }

            return(EnumerateNetworkObjectInternal(new FunctionData(), (NativeMethods.DfsInfo300 structure, IntPtr buffer) =>

                                                  new DfsInfo {
                EntryPath = structure.DfsName
            },

                                                  (FunctionData functionData, out IntPtr buffer, int prefMaxLen, out uint entriesRead, out uint totalEntries, out uint resumeHandle) =>
            {
                totalEntries = 0;

                // When host == null, the local computer is used.
                // However, the resulting OpenResourceInfo.Host property will be empty.
                // So, explicitly state Environment.MachineName to prevent this.
                // Furthermore, the UNC prefix: \\ is not required and always removed.
                string stripUnc = Utils.IsNullOrWhiteSpace(host) ? Environment.MachineName : Path.GetRegularPathInternal(host, GetFullPathOptions.CheckInvalidPathChars).Replace(Path.UncPrefix, string.Empty);

                return NativeMethods.NetDfsEnum(stripUnc, 300, prefMaxLen, out buffer, out entriesRead, out resumeHandle);
            }, continueOnException).Select(dfs => dfs.EntryPath));
        }
        public static IEnumerable <DfsInfo> EnumerateDfsLinks(string dfsName)
        {
            if (!Filesystem.NativeMethods.IsAtLeastWindowsVista)
            {
                throw new PlatformNotSupportedException(Resources.RequiresWindowsVistaOrHigher);
            }

            if (Utils.IsNullOrWhiteSpace(dfsName))
            {
                throw new ArgumentNullException("dfsName");
            }

            var fd = new FunctionData();

            return(EnumerateNetworkObjectInternal(fd, (NativeMethods.DfsInfo4 structure, IntPtr buffer) =>

                                                  new DfsInfo(structure),

                                                  (FunctionData functionData, out IntPtr buffer, int prefMaxLen, out uint entriesRead, out uint totalEntries, out uint resumeHandle1) =>
            {
                totalEntries = 0;
                return NativeMethods.NetDfsEnum(dfsName, 4, prefMaxLen, out buffer, out entriesRead, out resumeHandle1);
            }, false));
        }