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.
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
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.
Dig Deeper on Win Development Resources
Related Q&A from Mark Belles
This expert response shows how to access VB .NET Windows control on the client side. Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.