How can peer servers inside a work group be listed. I wanted to demonstrate a simple method to perform this operation.
System.Remoting namespace provides certain APIs using which this can be performed. At CodeProject, I saw a couple of articles performing similar operations in MC++ and they printout the IP addresses too.
The articles are available at these links:
I chose to use the Shell basics. Using Shell basics, several tasks can be done very simply. The Shell32 DLL is interoped with the project and it exposes a number of methods, classes and interfaces to perform a lot of operations, like using the Windows UI.
The Shell organizes these objects into a hierarchical structure called the namespace, which provides users and applications with a consistent and efficient way to access and manage objects. Users interact with the namespace through the Shell's graphical UI or through an application. Applications interact with the namespace through the Shell's application programming interface (API). This section is an introduction to the Shell API.
There are plenty of objects used to create applications and manage the operating system. The most familiar of these objects are the folders and files that reside on computer disk drives and over networks.
Some of the basics ,how-tos and the APIs used will be explained in this article.
The platform considered is Windows 2000 Server and such a server present under a workgroup server. The requirement is to view the peer servers under the workgroup. Shell basics are used to perform the above said task.
The workgroup when opened using an Explorer, displays the servers that are present in it. One has to understand the differences between:
- Link, etc.
An object of type
Shell32.Shell is created and another object of type
Shell32.Folder is also created. There are some special folders specified. Such as
ShellSpecialFolderConstants.ssfNETWORK represents the Network Places folder. My Documents, Control Panel and several special folders are defined and are identified by separate constants.
The folder is parsed only when
isFileSystem return false. The link is opened by using
Shell.NameSpace(object) and iterated until the workgroup server folder is reached.
Once the namespace is known, the
items() gives a collection, from which an individual
item can be retrieved. The code is given below:
Shell32.Shell sh = new Shell32.Shell();
Shell32.Folder currFolder =
int num =
MessageBox.Show("The Num of Items in special folder in the local",
int no =sh.NameSpace(currFolder.Items().Item(i)).Items().Count;
currFolder = sh.NameSpace(currFolder.Items().Item(i));
MessageBox.Show(myexcep.ToString()+" : Error");
There is a very simple method to find the IP address of the servers under the workgroup server. These are found in the
System.Net namespace. The peer servers are added in to a
ListView control as
Net Namespace contains a plethora of classes and APIs for network access. The IP address can be found by passing the domain name of the server.
giveAddress method returns the IP address of the Server.
this.listView1.DoubleClick += new System.EventHandler(this.giveAddress);
The following is an example of how it is done....
private void giveAddress(object sender, System.EventArgs e)
MessageBox displays the IP address of the selected server.
This is an illustration of the use of the Shell basics and a method for how the peers in a workgroup are listed and the IP addresses of the servers found.