Click to See Complete Forum and Search --> : computers in a workgroup


will200
02-07-2005, 01:07 PM
hi all,

i need help please ..

i need a peace of code that will list the name of all the computers in a workgroup.

Thanx in advance

Phil Weber
02-07-2005, 02:24 PM
A Google search for "c# enumerate workgroup" returned the following:

using System;
using System.DirectoryServices;

public class EnumComputers
{
public EnumComputers()
{
string path = "WinNT://[WorkGroupName|DomainName]";
string username = @"domain\username";
string password = "password";

DirectoryEntry domain = new DirectoryEntry(path, username, password);
DirectoryEntries computers = domain.Children;
computers.SchemaFilter.Add("Computer");

foreach(DirectoryEntry computer in computers)
{
Console.WriteLine(computer.Name);
}
}
}

Pvt_Ryan
02-10-2005, 06:34 PM
Is there any way to do this in VB.Net?
I have seen examples in VB6 but i cannot Port the into .Net

Phil Weber
02-10-2005, 06:40 PM
It's pretty trivial to translate the above code into VB.NET:

Dim path As String = "WinNT://[WorkGroupName|DomainName]"
Dim username As String = "domain\username"
Dim password As String = "password"

Dim domain As New DirectoryEntry(path, username, password)
Dim computers As DirectoryEntries = domain.Children
computers.SchemaFilter.Add("Computer")

For Each computer As DirectoryEntry In computers
Console.WriteLine(computer.Name)
Next

Pvt_Ryan
02-10-2005, 06:44 PM
Thanks the VB6 ones i looked at had Well more code and required defining custom types

System.DirectoryServices does not exist in vb.net or i am just being dumb and lookin in the wrong place

pclement
02-10-2005, 11:17 PM
It's a framework library - it isn't language specific. You can use it in VB.NET or C# but if I remember correctly you need to add the reference to the project.