Home > Ask the Microsoft .Net Development Experts > Visual Studio .NET Questions & Answers > What's the best approach for enumerating network resources?
Ask The Win Development Expert: Questions & Answers
EMAIL THIS

What's the best approach for enumerating network resources?

Mark Belles EXPERT RESPONSE FROM: Mark Belles

Pose a Question
Other Win Development Categories
Meet all Win Development Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 15 August 2004
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?

>
EXPERT RESPONSE
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


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Visual Studio .NET
Load a DSL domain model instance file programmatically
Best approach for merging text files using arrays
Descriptions of symbols in the class view of a .NET solution
How to enable a line-by-line code walkthrough
Changing a C++ Makefile project to a Utility project
How can I configure Visual Studio.NET 2002 to use the .NET Framework 1.1?
Changing a datagrid column to read-only=false based on variable
Resizing controls on a form
Can I use VS.NET on a server that's not upgraded to .NET Framework?
No extensibility folders

Visual Studio .NET
Load a DSL domain model instance file programmatically
Calling via command prompt from ASP.NET
On line-by-line analysis in VS .NET
Best approach for merging text files using arrays
Descriptions of symbols in the class view of a .NET solution
How to enable a line-by-line code walkthrough
Changing a C++ Makefile project to a Utility project
How can I configure Visual Studio.NET 2002 to use the .NET Framework 1.1?
Changing a datagrid column to read-only=false based on variable
No extensibility folders

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2000 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts