private static ICollection<string> EnumerateResources(NetResource pRsrc, ResourceScope scope, ResourceType type,
        ResourceUsage usage, ResourceDisplayType displayType)
    {
      List<string> result = new List<string>();
      uint bufferSize = 16384;
      IntPtr buffer = Marshal.AllocHGlobal((int) bufferSize);
      try
      {
        IntPtr handle;
        uint cEntries = 1;

        ErrorCodes res = WNetOpenEnum(scope, type, usage, pRsrc, out handle);

        if (res == ErrorCodes.NoError)
          try
          {
            do
            {
              res = WNetEnumResource(handle, ref cEntries, buffer, ref bufferSize);

              if (res == ErrorCodes.NoError)
              {
                Marshal.PtrToStructure(buffer, pRsrc);

                if (pRsrc.dwDisplayType == displayType)
                  result.Add(pRsrc.lpRemoteName);

                // If the current NetworkResource is a container, we call EnumerateResources recursively.
                // In some situations, the lpRemoteName in the NetworkResource is null or empty. In this case
                // we do not call EnumerateResources recursively as this leads to an infinite loop of
                // recursive calls. For details see Jira MP2-356
                if ((pRsrc.dwUsage & ResourceUsage.Container) == ResourceUsage.Container && !String.IsNullOrEmpty(pRsrc.lpRemoteName))
                  result.AddRange(EnumerateResources(pRsrc, scope, type, usage, displayType));
              }
              else if (res != ErrorCodes.ErrorNoMoreItems)
                break;
            } while (res != ErrorCodes.ErrorNoMoreItems);
          }
          finally
          {
            WNetCloseEnum(handle);
          }
      }
      finally
      {
        Marshal.FreeHGlobal(buffer);
      }
      return result;
    }
 public static ICollection<string> EnumerateResources(ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType)
 {
   NetResource pRsrc = new NetResource();
   return EnumerateResources(pRsrc, scope, type, usage, displayType);
 }
 private static extern ErrorCodes WNetOpenEnum(ResourceScope dwScope, ResourceType dwType, ResourceUsage dwUsage, NetResource p, out IntPtr lphEnum);
    private static ICollection<string> EnumerateResources(NetResource pRsrc, ResourceScope scope, ResourceType type,
        ResourceUsage usage, ResourceDisplayType displayType)
    {
      List<string> result = new List<string>();
      uint bufferSize = 16384;
      IntPtr buffer = Marshal.AllocHGlobal((int) bufferSize);
      try
      {
        IntPtr handle;
        uint cEntries = 1;

        ErrorCodes res = WNetOpenEnum(scope, type, usage, pRsrc, out handle);

        if (res == ErrorCodes.NoError)
          try
          {
            do
            {
              res = WNetEnumResource(handle, ref cEntries, buffer, ref bufferSize);

              if (res == ErrorCodes.NoError)
              {
                Marshal.PtrToStructure(buffer, pRsrc);

                if (pRsrc.dwDisplayType == displayType)
                  result.Add(pRsrc.lpRemoteName);

                if ((pRsrc.dwUsage & ResourceUsage.Container) == ResourceUsage.Container)
                  result.AddRange(EnumerateResources(pRsrc, scope, type, usage, displayType));
              }
              else if (res != ErrorCodes.ErrorNoMoreItems)
                break;
            } while (res != ErrorCodes.ErrorNoMoreItems);
          }
          finally
          {
            WNetCloseEnum(handle);
          }
      }
      finally
      {
        Marshal.FreeHGlobal(buffer);
      }
      return result;
    }
        public static ICollection <string> EnumerateResources(ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType)
        {
            NetResource pRsrc = new NetResource();

            return(EnumerateResources(pRsrc, scope, type, usage, displayType));
        }
 private static extern ErrorCodes WNetOpenEnum(ResourceScope dwScope, ResourceType dwType, ResourceUsage dwUsage, NetResource p, out IntPtr lphEnum);