Re: ADSI script implement in C#
- From: "John" <pursca2008@xxxxxxxxxxxxxxxx>
- Date: Wed, 28 May 2008 22:02:31 -0700
Hi, Steven,
in VB6 or VBscript,
Dim Group As IADsGroup
Dim objUser As Object
Set Group = GetObject("WinNT://DomainName/ComputerName/Administrators, group")
For Each objUser In Group.Members
MsgBox objUser.Name & " - " & objUser.ADsPath & " - " & objUser.Class
Next
returns correct information but
in C#,
string ADsPath = "WinNT://DomainName/ComputerName/Administrators, group";
DirectoryEntry de = new DirectoryEntry(ADsPath);
foreach (DirectoryEntry d in de.Children)
{
Console.WriteLine(d.Name + " " + d.Path);
}
this does not return anything
Could you please help understand why?
Thanks!
John
"Steven Cheng [MSFT]" <stcheng@xxxxxxxxxxxxxxxxxxxx> wrote in message news:khCTpkTwIHA.5796@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi John,.
From your description and the VB code snippet, you're going to use C# to
perform ADSI query on some domain computer's properties. As far as I know,
in .net, ADSI programming is provided by the System.DirectoryServices
namespace. And for accessing ADSI object, you can use the "DirectoryEntry"
class. Here is the C# code snippt that help query the certain domain
computer and loop its properties:
===============
static void RunADSI()
{
DirectoryEntry en = new DirectoryEntry();
en.Path = "WinNT://mydomain/mycomputer";
foreach (string key in en.Properties.PropertyNames)
{
Console.WriteLine("{0}: {1}",key, en.Properties[key].Value);
}
}
==============
the following ,knowledge base article provide the same information:
#How to access ADSI objects in Visual C#
http://support.microsoft.com/kb/315716
If you want more information and code about ADSI query in .net/c#, I
suggest you have a look at the following ADSI query tool, you can get more
ideas from its code:
#BeaverTail (written entirely in C#)
http://adsi.mvps.org/adsi/CSharp/beavertail.html
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------Reply-To: "John" <pursca@xxxxxxxxxxx>
From: "John" <pursca2008@xxxxxxxxxxxxxxxx>
Subject: ADSI script implement in C#
Date: Wed, 28 May 2008 17:15:00 -0700
group")
Hi, gurus,
How can I implement the following feature in C#:
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",
For Each objMember In objGroup.Members
WScript.Echo vbCrLf & " Name: " & objMember.Name
Next
Thanks!
John
- Follow-Ups:
- Re: ADSI script implement in C#
- From: Steven Cheng [MSFT]
- Re: ADSI script implement in C#
- References:
- ADSI script implement in C#
- From: John
- RE: ADSI script implement in C#
- From: Steven Cheng [MSFT]
- ADSI script implement in C#
- Prev by Date: Re: ADSI script implement in C#
- Next by Date: Re: ServiceController.ExecuteCommand() throws Exception,...
- Previous by thread: Re: ADSI script implement in C#
- Next by thread: Re: ADSI script implement in C#
- Index(es):
Relevant Pages
|