473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 4709
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 just opens the gui, so I'm not sure what the...
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 desktop I created a shortcut to the front end dbase...
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, Admin, and Users revoked. 'Ownership' of database...
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 and WID can create the same mdw file which I use...
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 user is prompted to enter a username and password...
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 the Access databases that I bring up under my...
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 directories on our network) which all require the user to...
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 how to do this in VB6, but these will not work...
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 machines and put them in a listbox. I am definitely a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.