472,328 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Enumerating Workgroup via C#?

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


Nov 15 '05 #1
3 4646
Hello Mark,

What you need to use is the System.EnterpriseServices namespace and use
either AD or LDAP to enumerate through the tree. There is also an ActiveX
DLL called activeds.tlb (I think that is the name...) which (IMHO) makes
things a bit simpler but has more of an overhead cost.

MSDN has documentation on both of these methods that you can use...

HTH,
Bill P.
"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

Nov 15 '05 #2
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

Nov 15 '05 #3

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:eX**************@TK2MSFTNGP12.phx.gbl...
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"]);

}
}
}


Great stuff - thanks very much. Once I knew where to look, I used the WIM
object browser and indeed there it was! One thing that I had to change was
the use of the boolean property PartOfDomain, which is available in Xp and
above only (not 2000). However, the property DomainRole does the trick
instead.

Cheers
Mark

[snip]
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Newbillian | last post by:
Is there some way of using vba to automate the processe of joining an Access 97 security workgroup? I typed wrkgadm /? at a command prompt and it...
1
by: Daniel | last post by:
Thank you for reading... I have developed two separate dbases using Access 2002. Each has their own workgroup specifications. On each users...
4
by: Chris Tyson | last post by:
My problem is this: I have created a database, using Workgroup security features. Unique Workgroup. New users added. Permissions to Admins,...
7
by: Paul T. Rong | last post by:
A card where I wrote my name and WID (work group ID) was stolen (unfortunately together with other things), therotically the one who have my name...
1
by: Dom | last post by:
Hi, I have a problem in getting Access 2002 to read my workgroup file. I've created different groups and users and when the db is opened the...
1
by: raydelex | last post by:
I am new to securing a database with logins. My questions is: I want only one database to use a new Workgroup file that I have created, not all...
3
by: JaBo | last post by:
Our company computers were recently upgraded to Windows XP with Microsoft Office 2003. We have 3 different Access Databases (in different...
1
by: Robert Fitzpatrick | last post by:
Hello, I'm looking for code examples that displays all the machines in a domain/workgroup using VB.NET. I've seen a few postings on the net on...
3
by: Joe User | last post by:
Hi - I found the class below on another website (www.devx.com) and can't seem to figure out how to make a call to this class to retrieve the...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.