473,573 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting local admin groups and users on a windows server using ADSI

hi all,
i am trying to get local admin users and groups on a windows server.
here is the C# code that i am using
*************** *************** *************** *************** *************** *************** *********
DirectoryEntry AD = new DirectoryEntry( "WinNT://" + sServerName +
",Computer",Use rName,Password) ;
DirectoryEntry admGroup = AD.Children.Fin d("Administrato rs", "Group");
object members = admGroup.Invoke ("Members", null);

foreach(object member in (System.Collect ions.IEnumerabl e)members)
{
DirectoryEntry user_groups = new DirectoryEntry( member);
// do some work.
}
*************** *************** *************** *************** *************** *************** ************

I have 2 issues here.
1. Its not getting all the local users and groups from the
Administrators group on the box.
2. How does it know which domain to look for with just "WinNT://" +
servername.... i have 2 domains, test and production and both domains
have same server names. i.e there is a AppServer in each of the test
and production domain.
3. Is there a different syntax to tell the DirectoryEntry object to
look at a particular server on a particular domain?

thanks,
shashank kadge

Mar 7 '07 #1
4 5676
"shashank kadge" <ma**********@g mail.comwrote in message
news:11******** **************@ t69g2000cwt.goo glegroups.com.. .
hi all,
i am trying to get local admin users and groups on a windows server.
here is the C# code that i am using
*************** *************** *************** *************** *************** *************** *********
DirectoryEntry AD = new DirectoryEntry( "WinNT://" + sServerName +
",Computer",Use rName,Password) ;
DirectoryEntry admGroup = AD.Children.Fin d("Administrato rs", "Group");
object members = admGroup.Invoke ("Members", null);

foreach(object member in (System.Collect ions.IEnumerabl e)members)
{
DirectoryEntry user_groups = new DirectoryEntry( member);
// do some work.
}
*************** *************** *************** *************** *************** *************** ************

I have 2 issues here.
1. Its not getting all the local users and groups from the
Administrators group on the box.
2. How does it know which domain to look for with just "WinNT://" +
servername.... i have 2 domains, test and production and both domains
have same server names. i.e there is a AppServer in each of the test
and production domain.
3. Is there a different syntax to tell the DirectoryEntry object to
look at a particular server on a particular domain?
All your questions are pretty well explained in the DirectoryEntry description in the MSDN
docs, search for "DirectoryEntry " and follow the "Path" property description.

Willy.

Mar 7 '07 #2
On Mar 7, 2:48 pm, "Willy Denoyette [MVP]"
<willy.denoye.. .@telenet.bewro te:
"shashank kadge" <mailtosha...@g mail.comwrote in message

news:11******** **************@ t69g2000cwt.goo glegroups.com.. .


hi all,
i am trying to get local admin users and groups on a windows server.
here is the C# code that i am using
*************** *************** *************** *************** *************** *************** **********
DirectoryEntry AD = new DirectoryEntry( "WinNT://" + sServerName +
",Computer",Use rName,Password) ;
DirectoryEntry admGroup = AD.Children.Fin d("Administrato rs", "Group");
object members = admGroup.Invoke ("Members", null);
foreach(object member in (System.Collect ions.IEnumerabl e)members)
{
DirectoryEntry user_groups = new DirectoryEntry( member);
// do some work.
}
*************** *************** *************** *************** *************** *************** *************
I have 2 issues here.
1. Its not getting all the local users and groups from the
Administrators group on the box.
2. How does it know which domain to look for with just "WinNT://" +
servername.... i have 2 domains, test and production and both domains
have same server names. i.e there is a AppServer in each of the test
and production domain.
3. Is there a different syntax to tell the DirectoryEntry object to
look at a particular server on a particular domain?

All your questions are pretty well explained in the DirectoryEntry description in the MSDN
docs, search for "DirectoryEntry " and follow the "Path" property description.

Willy.- Hide quoted text -

- Show quoted text -
thanks for the link.
i tried using the syntax on msdn but no luck.
i would appreciate if some1 can get some code or suggest a
modification on my code.

thanks,
shashank kadge

Mar 7 '07 #3
"shashank kadge" <ma**********@g mail.comwrote in message
news:11******** **************@ s48g2000cws.goo glegroups.com.. .
On Mar 7, 2:48 pm, "Willy Denoyette [MVP]"
<willy.denoye.. .@telenet.bewro te:
"shashank kadge" <mailtosha...@g mail.comwrote in message

news:11******** **************@ t69g2000cwt.goo glegroups.com.. .


hi all,
i am trying to get local admin users and groups on a windows server.
here is the C# code that i am using
*************** *************** *************** *************** *************** *************** **********
DirectoryEntry AD = new DirectoryEntry( "WinNT://" + sServerName +
",Computer",Use rName,Password) ;
DirectoryEntry admGroup = AD.Children.Fin d("Administrato rs", "Group");
object members = admGroup.Invoke ("Members", null);
foreach(object member in (System.Collect ions.IEnumerabl e)members)
{
DirectoryEntry user_groups = new DirectoryEntry( member);
// do some work.
}
*************** *************** *************** *************** *************** *************** *************
I have 2 issues here.
1. Its not getting all the local users and groups from the
Administrators group on the box.
2. How does it know which domain to look for with just "WinNT://" +
servername.... i have 2 domains, test and production and both domains
have same server names. i.e there is a AppServer in each of the test
and production domain.
3. Is there a different syntax to tell the DirectoryEntry object to
look at a particular server on a particular domain?

All your questions are pretty well explained in the DirectoryEntry description in the MSDN
docs, search for "DirectoryEntry " and follow the "Path" property description.

Willy.- Hide quoted text -

- Show quoted text -
thanks for the link.
i tried using the syntax on msdn but no luck.
i would appreciate if some1 can get some code or suggest a
modification on my code.

thanks,
shashank kadge

Because you have the same machine names in both domains, you'll have to set the IP address
instead of the machine name in the path.
And because you are binding using the WinNT provider, you'll have to set a reference to
activeds.tlb (%Windir%system 32)
Here's a small sample...

...
string groupName = "administrators ";
IADsMembers MembersCollecti on = null;
using(Directory Entry groupEntry = new DirectoryEntry( "WinNT://xxx.xxx.xxx.xxx/" +
groupName + ",group","Admin istrator", "pwd",
AuthenticationT ypes.Secure))
{
// invoke native method "members"
MembersCollecti on = groupEntry.Invo ke("Members") as IADsMembers;
object[] filter = {"User", "Group"};
MembersCollecti on.Filter = filter;
foreach (object obj in MembersCollecti on)
{
IADsGroup group = obj as IADsGroup;
if(group != null)
Console.WriteLi ne("group Name: {0}", group.Name);
//this is a group, so recurse to get the members of this group....
else
{
IADsUser user = obj as IADsUser;
Console.WriteLi ne("User Name: {0}", user.Name );
}
}
}
Willy.

Mar 7 '07 #4
On Mar 7, 5:26 pm, "Willy Denoyette [MVP]"
<willy.denoye.. .@telenet.bewro te:
"shashank kadge" <mailtosha...@g mail.comwrote in message

news:11******** **************@ s48g2000cws.goo glegroups.com.. .
On Mar 7, 2:48 pm, "Willy Denoyette [MVP]"

<willy.denoye.. .@telenet.bewro te:
"shashank kadge" <mailtosha...@g mail.comwrote in message
news:11******** **************@ t69g2000cwt.goo glegroups.com.. .
hi all,
i am trying to get local admin users and groups on a windows server.
here is the C# code that i am using
*************** *************** *************** *************** *************** *************** ***********
DirectoryEntry AD = new DirectoryEntry( "WinNT://" + sServerName +
",Computer",Use rName,Password) ;
DirectoryEntry admGroup = AD.Children.Fin d("Administrato rs", "Group");
object members = admGroup.Invoke ("Members", null);
foreach(object member in (System.Collect ions.IEnumerabl e)members)
{
DirectoryEntry user_groups = new DirectoryEntry( member);
// do some work.
}
*************** *************** *************** *************** *************** *************** **************
I have 2 issues here.
1. Its not getting all the local users and groups from the
Administrators group on the box.
2. How does it know which domain to look for with just "WinNT://" +
servername.... i have 2 domains, test and production and both domains
have same server names. i.e there is a AppServer in each of the test
and production domain.
3. Is there a different syntax to tell the DirectoryEntry object to
look at a particular server on a particular domain?
All your questions are pretty well explained in the DirectoryEntry description in the MSDN
docs, search for "DirectoryEntry " and follow the "Path" property description.
Willy.- Hide quoted text -
- Show quoted text -

thanks for the link.
i tried using the syntax on msdn but no luck.
i would appreciate if some1 can get some code or suggest a
modification on my code.

thanks,
shashank kadge

Because you have the same machine names in both domains, you'll have to set the IP address
instead of the machine name in the path.
And because you are binding using the WinNT provider, you'll have to set a reference to
activeds.tlb (%Windir%system 32)
Here's a small sample...

..
string groupName = "administrators ";
IADsMembers MembersCollecti on = null;
using(Directory Entry groupEntry = new DirectoryEntry( "WinNT://xxx.xxx..xxx.xx x/" +
groupName + ",group","Admin istrator", "pwd",
AuthenticationT ypes.Secure))
{
// invoke native method "members"
MembersCollecti on = groupEntry.Invo ke("Members") as IADsMembers;
object[] filter = {"User", "Group"};
MembersCollecti on.Filter = filter;
foreach (object obj in MembersCollecti on)
{
IADsGroup group = obj as IADsGroup;
if(group != null)
Console.WriteLi ne("group Name: {0}", group.Name);
//this is a group, so recurse to get the members of this group....
else
{
IADsUser user = obj as IADsUser;
Console.WriteLi ne("User Name: {0}", user.Name );
}
}
}

Willy.- Hide quoted text -

- Show quoted text -
Yeah, that helps.
Thanks for all the help Willy.

-
shashank kadge

Mar 8 '07 #5

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

Similar topics

6
2918
by: Rob | last post by:
Hi, I am working on a project that requires a Windows Service which performs the following file transfer functions. 1. It monitors a specific local directory on a Windows 2003 Server. 2. When it finds files with a specific extension, it queries a SQL Server database to determine what workstation will be the destination of a File.Copy....
0
1727
by: Dan Nordquist | last post by:
Hey everyone. I'm just getting my feet wet with ADSI (and VB.NET, and ASP.NET, really), but I'm wondering if there's a way to pull a list of distribution lists from an Exchange server using ADSI, LDAP, or anything else in ASP.NET with VB.NET. I'm creating a form that adds new users, and I'd like to be able to ask the user what mail...
8
9995
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/WebApplication1'. 'HTTP/1.1 500...
1
1334
by: Sunil Virmani | last post by:
I want to create a web service that can create the users in the Windows Domain. I am using ADSI for that. Using ADSI i am able to create the users eaisly. But when i incorporated the code in the web service i get the unauthorized error. How should i confiure the web service so that it can create the users in the windows domain.
5
3783
by: Rocky | last post by:
Hi, I have a webform, with 2 textboxs and a submit button. In the text box1, i enter a username and in textbox2 I enter the computer name. Both the username and computer name is in active directory. When i click submit, I want to add the username from textbox1 into the local administrators group on the computer name from textbox2. I...
1
4693
by: jodyblau | last post by:
I applogize for posting this a second time (I posted in the access-multiuser group as well), but this group seems to respond more rapidly, and I have been trying to figure this out for what seems like forever. I have the Access 2002 Developer's Handbook, and I am trying to learn from the example provided in Chapter 2, but I am running into...
4
10707
by: Odd Bjørn Andersen | last post by:
I have installed DB2 9 Enterprise Edition on my laptop (Windows xp prof. ed.). But when I try to connect to any of my local databases I get this error: SQL30082N Security processing failed with reason "19" ("USERID DISABLED or RESTRICTED"). SQLSTATE=08001 I am quite certain that this user is valid, I have used it to log on to the pc....
33
11830
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon (NT_AUTHORITY\SYSTEM). I understand that when the service starts, no user may be logged in, but that's ok, as the app I am monitoring can only be run...
1
1904
by: ringoschplingo | last post by:
Hi, (sorry this is a long one) I have MSSQL 2000 (version 8.00.2187) installed on Windows Server 2K3, nothing 'special' has been done to either of these servers as far as configuration goes. The exact details of the Windows server are Version - 5.2.3790, SP1. In order to query an Oracle db from SQL, I've set up a linked server within SQL...
0
7781
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8027
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
7788
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
8066
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
6421
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...
0
5292
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
3733
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
2216
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
0
1041
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.