A collection of shares
Inheritance: System.Collections.ReadOnlyCollectionBase
Example #1
0
        static void GetSharesInformationFromSpecifiedServer(string sFileServer, List <string> queryCollection)
        {
            var sc = new ShareCollection(sFileServer);

            if (sc.Count > 0)
            {
                queryCollection.AddRange(from Share s in sc
                                         where s.IsFileSystem
                                         select s.ToString());
            }
        }
        static void EnumerateSharesNt(string server, ShareCollection shares)
        {
            int    level   = 2;
            int    hResume = 0;
            IntPtr pBuffer = IntPtr.Zero;

            try
            {
                int entriesRead;
                int totalEntries;
                int nRet = NetShareEnum(server, level, out pBuffer, -1,
                                        out entriesRead, out totalEntries, ref hResume);

                if (ErrorAccessDenied == nRet)
                {
                    level = 1;
                    nRet  = NetShareEnum(server, level, out pBuffer, -1,
                                         out entriesRead, out totalEntries, ref hResume);
                }

                if (NoError == nRet && entriesRead > 0)
                {
                    Type t      = (2 == level) ? typeof(ShareInfo2) : typeof(ShareInfo1);
                    int  offset = Marshal.SizeOf(t);

                    for (int i = 0, lpItem = pBuffer.ToInt32(); i < entriesRead; i++, lpItem += offset)
                    {
                        IntPtr pItem = new IntPtr(lpItem);
                        if (1 == level)
                        {
                            ShareInfo1 si = (ShareInfo1)Marshal.PtrToStructure(pItem, t);
                            shares.Add(si.NetName, string.Empty, si.ShareType, si.Remark);
                        }
                        else
                        {
                            ShareInfo2 si = (ShareInfo2)Marshal.PtrToStructure(pItem, t);
                            shares.Add(si.NetName, si.Path, si.ShareType, si.Remark);
                        }
                    }
                }
            }
            finally
            {
                if (IntPtr.Zero != pBuffer)
                {
                    NetApiBufferFree(pBuffer);
                }
            }
        }
 protected static void EnumerateShares(string server, ShareCollection shares)
 {
     EnumerateSharesNt(server, shares);
 }
Example #4
0
        static void GetSharesInformationFromSpecifiedServer(string sFileServer, List<string> queryCollection)
        {
            var sc = new ShareCollection(sFileServer);

            if(sc.Count > 0)
            {
                queryCollection.AddRange(from Share s in sc
                                         where s.IsFileSystem
                                         select s.ToString());
            }
        }
 protected static void EnumerateShares(string server, ShareCollection shares)
 {
     EnumerateSharesNt(server, shares);
 }
        static void EnumerateSharesNt(string server, ShareCollection shares)
        {
            int level = 2;
            int hResume = 0;
            IntPtr pBuffer = IntPtr.Zero;

            try
            {
                int entriesRead;
                int totalEntries;
                int nRet = NetShareEnum(server, level, out pBuffer, -1,
                    out entriesRead, out totalEntries, ref hResume);

                if(ErrorAccessDenied == nRet)
                {
                    level = 1;
                    nRet = NetShareEnum(server, level, out pBuffer, -1,
                        out entriesRead, out totalEntries, ref hResume);
                }

                if(NoError == nRet && entriesRead > 0)
                {
                    Type t = (2 == level) ? typeof(ShareInfo2) : typeof(ShareInfo1);
                    int offset = Marshal.SizeOf(t);

                    for(int i = 0, lpItem = pBuffer.ToInt32(); i < entriesRead; i++, lpItem += offset)
                    {
                        IntPtr pItem = new IntPtr(lpItem);
                        if(1 == level)
                        {
                            ShareInfo1 si = (ShareInfo1)Marshal.PtrToStructure(pItem, t);
                            shares.Add(si.NetName, string.Empty, si.ShareType, si.Remark);
                        }
                        else
                        {
                            ShareInfo2 si = (ShareInfo2)Marshal.PtrToStructure(pItem, t);
                            shares.Add(si.NetName, si.Path, si.ShareType, si.Remark);
                        }
                    }
                }
            }
            finally
            {
                if(IntPtr.Zero != pBuffer)
                {
                    NetApiBufferFree(pBuffer);
                }
            }
        }