Use the Management namespace and WMI for this, following is a sample.
// On Windows XP and W2K3
using System;
using System.Management;
class App {
public static void Main() {
SelectQuery query = new SelectQuery("Win32_ComputerSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mo in searcher.Get()) {
if((bool)mo["partofdomain"] != true)
Console.WriteLine("Workgroup {0} ",mo["workgroup"]);
else
Console.WriteLine("Domain {0} ",mo["workgroup"]);
}
}
}
// On Windows NT and Windows 98 (WMI core redistributable required)
using System;
using System.Management;
class App {
public static void Main() {
SelectQuery query = new SelectQuery("Win32_ComputerSystem");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mo in searcher.Get()) {
Console.WriteLine("{0} ",mo["domain"]); // this returns the domain name or workgroup name
}
}
}
Willy.
"Mark" <ma**@ReMoVeThIsBiTmossywell.com> wrote in message news:3f*********************@news.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