1

In my C# WPF application, I've written a dialog that allows the user to pick a folder from the local hard drive. The custom dialog keeps my application's look & feel, and provides features that the common dialog doesn't that aren't important to this question.

I am now adding functionality for a new feature of the program, which requires that the dialog includes the names of computers that are visible to the local machine / user in the dialog's TreeView control. Expanding the entry for the computer should list all of the shares that are visible to the local machine / user.

In other words, I'd like this new feature to work like the Windows Explorer window does when you expand the "Network" option.

How do I discover the names of the computers that are out there that the machine can see, and the shares on it that the user can access?

EDIT 1:

I do need a bit more information than just the computer name. Thank you, Jonathan Reinhart, for the question you linked to. I didn't find that in my own search.

To be clear, in addition to the names of the computers on the network, I need to know the names of the shares on each that the current user has rights to see. The answer linked to in the comments does not tell me anything about obtaining shares. I also have no experience with Directory Services, so I don't know what I'm missing.

EDIT 2:

There are other problems with the code linked to in the comment. It loops over the Active Directory to find the computers without making any check as to whether the current user has access to each. The list of computers returned includes all computer accounts in the Active Directory, including ones for machines that are not turned on. And it's slow. At my location, the code I wrote has to loop through all of the users & groups before it gets to the computer accounts.

I need the exact list of computers that Windows Explorer returns when that user expands the Network choice, as well as the list of shares for each that appears when the user expands the tree node for the computer.

How do I get this list?

EDIT 3:

I've found a CodeProject article that has the code I need. Since this question was closed, I can't create an answer. However, here is a link to the article. Essentially, I have to make a P/INVOKE call to WNetOpenEnum, followed by one or more calls to WNetEnumResource, and a call to WNetCloseEnum when it's all done. The article linked to contains C# code for performing these operation.

Tony Vitabile
  • 8,298
  • 15
  • 67
  • 123

0 Answers0