Ask the Expert

What's the best approach for enumerating network resources?

I would like to identify servers in my system in runtime and list them in a combo box. Once in the box, I would like to be able to simply click on one of the servers/data bases and connect to it. Do you have any suggestions for approaching this project?
There are several means for enumerating network resources. Some are indeed easier than others, but let me just throw out a few means that I know are proven. You could start out with the good old Win32 API in C/C++ and call the NetServerEnum method which will allow you to enumerate network resources such as domain controllers, SQL servers, or printers to name a few. However, that isn't going to be easy to consume from a managed language. Enter P/Invoke and Interop.

The next logical step would be to create a managed C++ wrapper class that would call the native APIs and then return the results in managed classes any .NET language could consume.

You could of course do all the work in VB.NET or C# using straight interop, but that will take more time than the previous suggestions.

You could also use Windows Management Instrumentation (WMI) or Windows Scripting Host (WScript.NETwork object to be more precise.)

If you are curious, there are many articles leading to free source code from other sites like www.codeproject.com or www.codeguru.com that would have example programs that demonstrate this. If you google the phrase "NetServerEnum C#" you should find several links to helpful articles covering this topic.

I would recommend the managed C++ wrapper or the pure C# classes using Interop. Keep things in a managed environment and you will thank yourself later!

Several good starting articles to read with source code examples can be found here. Both implement some of the techniques I have mentioned above.

http://codeproject.com/csharp/CompPickerLib.asp
http://www.codeproject.com/cs/database/LocatingSql.asp#xx702616xx

This was first published in August 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: