Exemplo n.º 1
0
        public static IEnumerable <NetworkComputerInfo> GetNetworkComputerInfo(ServerTypes serverTypes = ServerTypes.Workstation | ServerTypes.Server, string domain = null)
        {
            IntPtr bufptr = IntPtr.Zero;

            try
            {
                int    entriesRead, totalEntries;
                IntPtr resumeHandle = IntPtr.Zero;

                int ret = NetServerEnum(null, 101, out bufptr, MAX_PREFERRED_LENGTH, out entriesRead, out totalEntries, serverTypes, domain, resumeHandle);
                if (ret == 0)
                {
                    return(InteropUtil.ToArray <NetworkComputerInfo>(bufptr, entriesRead));
                }
                throw new System.ComponentModel.Win32Exception(ret);
            }
            finally
            {
                NetApiBufferFree(bufptr);
            }
        }
Exemplo n.º 2
0
        public static IEnumerable <string> GetNetworkComputerNames(ServerTypes serverTypes = ServerTypes.Workstation | ServerTypes.Server, string domain = null)
        {
            IntPtr bufptr = IntPtr.Zero;

            try
            {
                int    entriesRead, totalEntries;
                IntPtr resumeHandle = IntPtr.Zero;

                int ret = NetServerEnum(null, 100, out bufptr, MAX_PREFERRED_LENGTH, out entriesRead, out totalEntries, serverTypes, domain, resumeHandle);
                if (ret == 0)
                {
                    return(Array.ConvertAll <SERVER_INFO_100, string>(InteropUtil.ToArray <SERVER_INFO_100>(bufptr, entriesRead), si => si.sv100_name));
                }
                throw new System.ComponentModel.Win32Exception(ret);
            }
            finally
            {
                NetApiBufferFree(bufptr);
            }
        }