FINALLY! A way to get domains, computers, etc. from the network easily through code!

bri189a

Well-known member
Joined
Sep 11, 2003
Messages
1,004
Location
VA
Voca (from previous post) - your method doesnt get the shared folders though... I already did something like that... but thanks... as I said I figured out what Im doing wrong and as a gift to you all here is a DLL that will make your lifes so much easier;

I put about 16 hours on this because its all API... and that meant a lot of Marshalling...pointers, and memory management; an example on how to use the code is below... as you can see I kept with the GetFiles(), GetDirectories() type of mentality and I even made its name space System.IO, please pass this on and if you use it, just credit me somewhere.

The zip file also has an XML file for the documentation. I did not build any error checking into this, so follow the instructions, but it is really common sense... also since it is all low level API on the inside if you screw up there is a possiblity of a memory leak... I went to great extremes to make sure to DeAllocate the memory that was in case of unexpected errors and in normal operation, in which case there is no need to worry, but still I want to put that warning out. I have tested this on my network at work which has hundreds of computers on it and everything worked great... remember to wait on the return on distance domains.... lag time people... to cause errors by exiting early because of lag time! I hope this helps many people, and when someone is searching for something to do this for four days (such as I was) I can save them some grief; let me know what you think!

Code Use Example:
C#:
SharedFolder [] folders = Network.GetSharedFolders(@"\\WILLYWONKASCOMPUTER");
			int count = 0;
			if(folders!=null)
			{
				foreach(SharedFolder s in folders)
				{
					Console.WriteLine(s.Name);
					count++;
				}
			}
			Console.WriteLine("Total Count = {0}", count);
			Console.ReadLine();
:D :D :D :D :D

[edit]Attachement removed - no binary files allowed in attachements. Please repost the attachement with soruce code if you wish. - mutant[/edit]
 
Last edited by a moderator:
Voca, yes... it works great (now that I found my bug :))... everyone else... if you downloaded the zip file prior to mutant removing it, please PM me your email and Ill send you an update that will allow you to use it in a ListView control without it crashing your program if you re-add the items to your ListView. There is still a bug with getting Domains, but getting Servers, and getting SharedFolders are working wonderfully now. For those of you who might have found my bug... two words... memory allocation... when MSDN says they can dynamically allocate memory in there API... use it! Because if you give it too little, or too much as was my case it will cause a stack overflow somewhere down the line and drive you nuts for five days like it did me. The GetDomains() bug only is a problem if when you open your Network Neighborhood and you have more than Microsoft Windows Network there... such is my case at home where the first thing I have is Microsoft Remote Networking, which it trys to look for domains on... Ill get to that later... most people who will use this already know the domain they want... its the servers or shared folders they need.
 
Back
Top