Use the Management namespace and WMI for this, following is a sample.
// On Windows XP and W2K3
using System;
using System.Manageme nt;
class App {
public static void Main() {
SelectQuery query = new SelectQuery("Wi n32_ComputerSys tem");
ManagementObjec tSearcher searcher = new ManagementObjec tSearcher(query );
foreach (ManagementObje ct mo in searcher.Get()) {
if((bool)mo["partofdoma in"] != true)
Console.WriteLi ne("Workgroup {0} ",mo["workgroup"]);
else
Console.WriteLi ne("Domain {0} ",mo["workgroup"]);
}
}
}
// On Windows NT and Windows 98 (WMI core redistributable required)
using System;
using System.Manageme nt;
class App {
public static void Main() {
SelectQuery query = new SelectQuery("Wi n32_ComputerSys tem");
ManagementObjec tSearcher searcher = new ManagementObjec tSearcher(query );
foreach (ManagementObje ct mo in searcher.Get()) {
Console.WriteLi ne("{0} ",mo["domain"]); // this returns the domain name or workgroup name
}
}
}
Willy.
"Mark" <ma**@ReMoVeThI sBiTmossywell.c om> wrote in message news:3f******** *************@n ews.dial.pipex. com...
I have a server in a workgroup (called "wg"). Does anyone know how to find
the name of the workgroup from code (pref c#)? I've trawled the newsgroups
and the MSDN site for the right class / method / property to use but I just
can't find the right one. There are plenty (such as UserDomainName) that
give me the server name, but none that I can find to give me the actual
workgroup name.
TIA
Mark