473,322 Members | 1,504 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,322 software developers and data experts.

NetQueryDisplayInformation Question

All:

I am very new to C#, but not OO languages in general. I am working on a
project where I need to enumerate the members of a local group on
workstations. I was reading through the MSDN database and found the
NetQueryDisplayInformation API call.

I realize I can use the netapi32.dll from within C# but am a bit clear
as to how I can go about reading the information presented back from the
execution.

Does anyone know of, or have any examples that use the
NetQueryDisplayInformation API call?

Thanks,
Sam
Nov 16 '05 #1
4 4918
Forget about the NetXXX API's, most of their functionality is covered by the
FCL classes and COM interop.
Enumerating local security databases can be done using the
System.DirectoryServices namespace classes with the WinNT adsi provider.
Search msdn for samples.

Willy.

"Sam Evans" <wi******@gmail.com> wrote in message
news:Qc********************@giganews.com...
All:

I am very new to C#, but not OO languages in general. I am working on a
project where I need to enumerate the members of a local group on
workstations. I was reading through the MSDN database and found the
NetQueryDisplayInformation API call.

I realize I can use the netapi32.dll from within C# but am a bit clear as
to how I can go about reading the information presented back from the
execution.

Does anyone know of, or have any examples that use the
NetQueryDisplayInformation API call?

Thanks,
Sam

Nov 16 '05 #2
Thank you for the reply, Willy.

From reading the ADSI information it seems like it is geared towards
enumerating information from Active Directory its self rather than
having anything to do with a local machine.

I'm trying to enumerate members of a group from a local machine (i.e.,
connecting to the local machine and finding out who the members are of
its local Administrators group).

Would the ADSI still work for me in this situation?

Thanks,
Sam
Willy Denoyette [MVP] wrote:
Forget about the NetXXX API's, most of their functionality is covered by the
FCL classes and COM interop.
Enumerating local security databases can be done using the
System.DirectoryServices namespace classes with the WinNT adsi provider.
Search msdn for samples.

Willy.

"Sam Evans" <wi******@gmail.com> wrote in message
news:Qc********************@giganews.com...
All:

I am very new to C#, but not OO languages in general. I am working on a
project where I need to enumerate the members of a local group on
workstations. I was reading through the MSDN database and found the
NetQueryDisplayInformation API call.

I realize I can use the netapi32.dll from within C# but am a bit clear as
to how I can go about reading the information presented back from the
execution.

Does anyone know of, or have any examples that use the
NetQueryDisplayInformation API call?

Thanks,
Sam


Nov 16 '05 #3

"Sam Evans" <wi******@gmail.com> wrote in message
news:U-********************@giganews.com...
Thank you for the reply, Willy.

From reading the ADSI information it seems like it is geared towards
enumerating information from Active Directory its self rather than having
anything to do with a local machine.

I'm trying to enumerate members of a group from a local machine (i.e.,
connecting to the local machine and finding out who the members are of its
local Administrators group).

Would the ADSI still work for me in this situation?


ADSI and the ADSI wrappers in System.DirectoryServices are not only
targetting LDAP servers (AD) but also the local security administrative
service & SAM database. This is done through two different client providers,
one is the LDAP provider the other is the WinNT provider. The first can (and
should ) be used when connecting to the AD (or any LDAP v2 compliant)
directory service. The latter can be used to connect to a NT4 domain (and AD
domain, but this is not advisable) or local server.

Here's a sample that enumerates a local alias:

private static void ListMembersInGroup2(string GroupName)
{
// Connect to a local server using the WinNT provider interface
using(DirectoryEntry groupEntry = new
DirectoryEntry("WinNT://YourMachineName/" + GroupName + ",group"))
{
object members = groupEntry.Invoke("Members");
foreach( object member in (IEnumerable) members)
{
DirectoryEntry x = new DirectoryEntry(member);
Console.WriteLine("ADsPath "+ x.Path + " Name: " + x.Name);
}
}
}

public static void Main()
{
ListMembersInGroup("Users"); // enum 'users' alias
}

And here a more elaborated sample. This one uses COM interop to access the
native ds classes from activeds.dll, so you need to add a reference to
activeds.tlb (in system32) and you have to add a using clause to import that
namespace.

private static void ListMembersInGroup2(string GroupName)
{
IADsMembers MembersCollection = null;
using(DirectoryEntry groupEntry = new DirectoryEntry("WinNT://acer1/" +
GroupName + ",group"))
{
// invoke native method "members"
MembersCollection = groupEntry.Invoke("Members") as IADsMembers;
object[] filter = {"User"}; // return only User objects
MembersCollection.Filter = filter;
foreach (IADsUser member in MembersCollection) {
DirectoryEntry x = new DirectoryEntry(member);
foreach(string s in x.Properties.PropertyNames)
{
Console.WriteLine("{0} \t\t {1}", s, x.Properties[s].Value);
}
}
}

Willy.
Nov 16 '05 #4
Willy,

This is perfect. It sets me on the right course, and is *much* easier
to use than the netapi32.dll.

Thank you very much for your help!!

Willy Denoyette [MVP] wrote:
- SNIP -
ADSI and the ADSI wrappers in System.DirectoryServices are not only
targetting LDAP servers (AD) but also the local security administrative
service & SAM database. This is done through two different client providers,
one is the LDAP provider the other is the WinNT provider. The first can (and
should ) be used when connecting to the AD (or any LDAP v2 compliant)
directory service. The latter can be used to connect to a NT4 domain (and AD
domain, but this is not advisable) or local server.

Here's a sample that enumerates a local alias:

private static void ListMembersInGroup2(string GroupName)
{
// Connect to a local server using the WinNT provider interface
using(DirectoryEntry groupEntry = new
DirectoryEntry("WinNT://YourMachineName/" + GroupName + ",group"))
{
object members = groupEntry.Invoke("Members");
foreach( object member in (IEnumerable) members)
{
DirectoryEntry x = new DirectoryEntry(member);
Console.WriteLine("ADsPath "+ x.Path + " Name: " + x.Name);
}
}
}

public static void Main()
{
ListMembersInGroup("Users"); // enum 'users' alias
}

And here a more elaborated sample. This one uses COM interop to access the
native ds classes from activeds.dll, so you need to add a reference to
activeds.tlb (in system32) and you have to add a using clause to import that
namespace.

private static void ListMembersInGroup2(string GroupName)
{
IADsMembers MembersCollection = null;
using(DirectoryEntry groupEntry = new DirectoryEntry("WinNT://acer1/" +
GroupName + ",group"))
{
// invoke native method "members"
MembersCollection = groupEntry.Invoke("Members") as IADsMembers;
object[] filter = {"User"}; // return only User objects
MembersCollection.Filter = filter;
foreach (IADsUser member in MembersCollection) {
DirectoryEntry x = new DirectoryEntry(member);
foreach(string s in x.Properties.PropertyNames)
{
Console.WriteLine("{0} \t\t {1}", s, x.Properties[s].Value);
}
}
}

Willy.

Nov 16 '05 #5

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

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
2
by: Chris van den Heuvel | last post by:
I am trying to enumerate the users of a system from within my app (VB.NET) Not finding any .Net Framework classes to do this I turned to the Win32 API and NetQueryDisplayInformation. I can't get it...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
2
by: Chris van den Heuvel | last post by:
I am trying to enumerate the users of a system from within my app (VB.NET) Not finding any .Net Framework classes to do this I turned to the Win32 API and NetQueryDisplayInformation. I can't get it...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.