1

I'm kind of lost, I have a task to get all folders from a network domain, E.g. (My Network Places/Entire Network/Microsoft Windows Network/xyNetwork).

I have to get all folders and sub-folders then get all security groups assigned to this folder and the rights granted to each security group.

The second part I have done before, however, the first part which is getting a list of all folders seems to be very complicated.

Any guides or references that might help?

Grant H.
  • 3,689
  • 2
  • 35
  • 53
Maro
  • 2,579
  • 9
  • 42
  • 79
  • 1
    possible duplicate of [List all computers in active directory](http://stackoverflow.com/questions/1605567/list-all-computers-in-active-directory) – mbeckish Jan 15 '13 at 15:51
  • Not clear and way to broad. Start the first specific problem and what have you tired. – paparazzo Jan 15 '13 at 16:50

2 Answers2

2

Well, there is a code in another similar entry that lists all the computer names from the network... That's the first part of your requirement. For the second part I think you need to dig into System.DirectoryServices classes since there are some for permissions as well... good luck.

//Lists all available computer names on the network.
public static List<String> ListNetworkComputers()
{
    var computerNames = new List<String>();
    var computerSchema = "Computer";

    var entries = new System.DirectoryServices.DirectoryEntry("WinNT:");
    foreach (var domains in entries.Children)
    {
        foreach (var computer in domains.Children)
        {
            if (computer.SchemaClassName.ToLower().Contains(computerSchema .ToLower()))
            {
                computerNames.Add(computer.Name);
            }
        }
    }

    return computerNames;
}

I just printed out the values and it worked fine for me.

foreach (string lst in ListNetworkComputers())
{
    Console.WriteLine("PC: " + lst);
}

(Above code taken from: Getting computer names from my network places )

What you need is to access the Win32_Share WMI from your code. Add the reference to System.Management.dll and use the following code.

code example in VB.NET from the topic here: http://www.pcreview.co.uk/forums/finding-share-s-directory-spec-t3064222.html

C# version of the VB.net program:

class Program
{
    static void Main(string[] args)
    {
        var objClass = new System.Management.ManagementClass("Win32_Share");

        foreach(var objShare in objClass.GetInstances())
        {
            Console.WriteLine(String.Format("{0} -> {1}", 
                objShare.Properties["Name"].Value, objShare.Properties["Path"].Value));
        }
    }
}

You can compare the results of the code above against the result that you get by running the following command in a windows command prompt:

C:\net share

Which will give you the Share Name (shared name given when sharing i.e. MySharedDir) and the Resource (windows path i.e. C:\myshareddir).

Community
  • 1
  • 1
Carlos Quintanilla
  • 12,937
  • 3
  • 22
  • 25
  • It seems that i'm not making my self clear. What i want is the following. open My network places, then microsoft windows network then you should see alot of network domain, select one of them which contain thousands of PC , servers .. etc (then for each one i want to get the list of folders and sub folders) – Maro Jan 15 '13 at 16:03
  • @Maro - What about the link to the Active Directory question? Does that answer your question? – mbeckish Jan 15 '13 at 16:33
  • @Maro, you are welcome. a broadcast to get all computers on the network is time consuming by nature... why not adding a "This will take some time. Please wait." message and scrollbar? hehe – Carlos Quintanilla Jan 16 '13 at 14:18
  • It's not an application that will be used by users to display a message, it's an application that will run every night to get data from all servers in the company – Maro Jan 16 '13 at 15:17
0

you can simply use GetDirectories. For example:

var folders = Directory.GetDirectories(@"\\server\share");

to get all directories (i.e. include subdirectories), use the following:

var folders = Directory.GetDirectories(@"\\server\share", "*", SearchOption.AllDirectories));
vlad
  • 4,748
  • 2
  • 30
  • 36
  • It's not getting a directory from a server, it's getting all workstation that are in a network then get all directories of these work station – Maro Jan 15 '13 at 15:37