473,549 Members | 2,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4724
Hello Mark,

What you need to use is the System.Enterpri seServices 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**@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

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.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

Nov 15 '05 #3

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

}
}
}


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
10079
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 parameters are for the command or whether there really are any command line switches for it. Thank you in advance.
1
1789
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 and with the appropriate workgroup: Path of shortcut is: "locationofMSACCESS.EXE" "locationoffrontend.mdb" /wrkgrp "locationofworkgroup.mdw"
4
1487
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 objects has been given to a custom User, and has not been left as owned by Admins. I transfer this file (and its Workgroup) to a shared drive on a...
7
2026
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 with my database. Who can tell me can it have any influnce on the security of my database? If nothing, I will just ignore it.
1
2342
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 which seems to be working perfectly on my PC. However, when someone else on a different computer opens this db on the shared network the user is no...
1
2520
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 system login. Can this be done? Thanks
3
4286
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 be part of a "Workgroup". It appears that Access 2003 includes some added security features that prevent the user from accessing a database unless...
1
1139
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 for us. Thanks RF
3
2766
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 beginner in vb programming, and would really appreciate the help. TIA!
0
7459
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7726
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7485
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7819
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5377
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1953
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.