/// <summary> /// Enumerates all computers visible to the specified computer on the specified domain. /// </summary> /// <param name="computer">Optional computer name. The local computer is assumed if this parameter is null.</param> /// <param name="domain">Optional domain name. The primary domain of the specified computer is assumed if this parameter is null.</param> /// <returns>An array of ServerInfo1 objects.</returns> /// <remarks></remarks> public static ServerInfo101[] EnumServers() { MemPtr adv; var mm = new MemPtr(); int en = 0; int ten = 0; ServerInfo101[] servers; int i; int c; var inul = new IntPtr(); NetServerEnum(null, 101, ref mm, -1, ref en, ref ten, ServerTypes.WindowsNT, null, ref inul); adv = mm; c = ten; servers = new ServerInfo101[c + 1]; for (i = 0; i < c; i++) { servers[i] = adv.ToStruct <ServerInfo101>(); adv = adv + Marshal.SizeOf <ServerInfo101>(); } mm.NetFree(); return(servers); }
/// <summary> /// Gets network information for the specified computer. /// </summary> /// <param name="computer">Computer for which to retrieve the information.</param> /// <param name="info">A ServerInfo101 structure that receives the information.</param> /// <remarks></remarks> public static void GetServerInfo(string computer, ref ServerInfo101 info) { var mm = new MemPtr(); NetInfo.NetServerGetInfo(computer, 101, ref mm); info = mm.ToStruct <ServerInfo101>(); mm.NetFree(); }