Example #1
0
        public static HostShare[] EnumNetShares(string Server)
        {
            List <HostShare> ShareInfos = new List <HostShare>();
            int           entriesread   = 0;
            int           totalentries  = 0;
            int           resume_handle = 0;
            int           nStructSize   = Marshal.SizeOf(typeof(ShareInfo));
            IntPtr        bufPtr        = IntPtr.Zero;
            StringBuilder server        = new StringBuilder(Server);
            int           ret           = NetShareEnum(server, 1, ref bufPtr, MAX_PREFERRED_LENGTH, ref entriesread, ref totalentries, ref resume_handle);

            if (ret == NERR_Success)
            {
                IntPtr currentPtr = bufPtr;
                for (int i = 0; i < entriesread; i++)
                {
                    ShareInfo shi1 = (ShareInfo)Marshal.PtrToStructure(currentPtr, typeof(ShareInfo));

                    ShareInfos.Add(new HostShare(shi1, Server));
                    currentPtr += nStructSize;
                }
                NetApiBufferFree(bufPtr);
                return(ShareInfos.ToArray());
            }
            else
            {
                throw new ShareEnumException("ERROR=" + ret.ToString());
            }
        }
Example #2
0
 public HostShare(ShareInfo shareInfo, string hostname)
 {
     this.shareInfo = shareInfo;
     this.hostname  = hostname;
 }