How to enumerate Windows user accounts? - DOTNET

This is a discussion on How to enumerate Windows user accounts? - DOTNET ; I'm trying to get a list of user accounts on the local computer - the same list you see when you are about to log in to Windows XP or Vista. This needs to work on a home computer (not ...

+ Reply to Thread
Results 1 to 3 of 3

How to enumerate Windows user accounts?

  1. Default How to enumerate Windows user accounts?

    I'm trying to get a list of user accounts on the local computer - the same
    list you see when you are about to log in to Windows XP or Vista. This needs
    to work on a home computer (not connected to a domain). It's for a parental
    control app where I want the parent to be able to assign rules for each
    child's account. I've tried using the Win32 API
    LsaEnumerateAccountsWithUserRight with the SE_INTERACTIVE_LOGON_NAME
    privilege, but it doesn't work. I tried passing in NULL as the UserRights
    parameter, which is supposed to return ALL accounts, but I get back a list
    which has the built-in accounts and a few others (see below), but not one
    single normal user account. I just want the accounts for people who can log
    on interactively. I'd prefer if there was a fully .NET C# solution but I'll
    do Win32 if I have to. Should I be using LsaLookupNames2 instead?

    NT AUTHORITY\SERVICE
    BUILTIN\Remote Desktop Users
    BUILTIN\Backup Operators
    BUILTIN\Users
    BUILTIN\Administrators
    Justin-Laptop\Guest
    Justin-Laptop\SQLServer2005MSSQLUser$Justin-Laptop$SQLEXPRESS
    Justin-Laptop\SQLServer2005SQLBrowserUser$Justin-Laptop
    NT AUTHORITY\NETWORK SERVICE
    NT AUTHORITY\LOCAL SERVICE
    Everyone

  2. Default RE: How to enumerate Windows user accounts?

    This code seems to be heading in the right direction. But I really need the
    SID for each account. And I'm not sure what groups to enumerate to match what
    you see when you log in to Windows XP or Vista. This ActiveDirectory stuff is
    new to me.

    DirectoryEntry localMachine = new DirectoryEntry("WinNT://" +
    Environment.MachineName);
    DirectoryEntry admGroup = localMachine.Children.Find("administrators",
    "group");
    object members = admGroup.Invoke("members", null);
    foreach (object groupMember in (IEnumerable)members) {
    DirectoryEntry member = new DirectoryEntry(groupMember);
    Console.WriteLine(member.Name);
    }


    "jmagaram" wrote:

    > I'm trying to get a list of user accounts on the local computer - the same
    > list you see when you are about to log in to Windows XP or Vista. This needs
    > to work on a home computer (not connected to a domain). It's for a parental
    > control app where I want the parent to be able to assign rules for each
    > child's account. I've tried using the Win32 API
    > LsaEnumerateAccountsWithUserRight with the SE_INTERACTIVE_LOGON_NAME
    > privilege, but it doesn't work. I tried passing in NULL as the UserRights
    > parameter, which is supposed to return ALL accounts, but I get back a list
    > which has the built-in accounts and a few others (see below), but not one
    > single normal user account. I just want the accounts for people who can log
    > on interactively. I'd prefer if there was a fully .NET C# solution but I'll
    > do Win32 if I have to. Should I be using LsaLookupNames2 instead?
    >
    > NT AUTHORITY\SERVICE
    > BUILTIN\Remote Desktop Users
    > BUILTIN\Backup Operators
    > BUILTIN\Users
    > BUILTIN\Administrators
    > Justin-Laptop\Guest
    > Justin-Laptop\SQLServer2005MSSQLUser$Justin-Laptop$SQLEXPRESS
    > Justin-Laptop\SQLServer2005SQLBrowserUser$Justin-Laptop
    > NT AUTHORITY\NETWORK SERVICE
    > NT AUTHORITY\LOCAL SERVICE
    > Everyone


  3. Default RE: How to enumerate Windows user accounts?

    Try this inside the for loop:

    string sid = new
    SecurityIdentifier((byte[])member.Properties["objectSid"][0], 0).Value;
    Console.WriteLine (sid);

    This works with .NET 2.0 onwards.

    "jmagaram" wrote:

    > This code seems to be heading in the right direction. But I really need the
    > SID for each account. And I'm not sure what groups to enumerate to match what
    > you see when you log in to Windows XP or Vista. This ActiveDirectory stuff is
    > new to me.
    >
    > DirectoryEntry localMachine = new DirectoryEntry("WinNT://" +
    > Environment.MachineName);
    > DirectoryEntry admGroup = localMachine.Children.Find("administrators",
    > "group");
    > object members = admGroup.Invoke("members", null);
    > foreach (object groupMember in (IEnumerable)members) {
    > DirectoryEntry member = new DirectoryEntry(groupMember);
    > Console.WriteLine(member.Name);
    > }
    >
    >
    > "jmagaram" wrote:
    >
    > > I'm trying to get a list of user accounts on the local computer - the same
    > > list you see when you are about to log in to Windows XP or Vista. This needs
    > > to work on a home computer (not connected to a domain). It's for a parental
    > > control app where I want the parent to be able to assign rules for each
    > > child's account. I've tried using the Win32 API
    > > LsaEnumerateAccountsWithUserRight with the SE_INTERACTIVE_LOGON_NAME
    > > privilege, but it doesn't work. I tried passing in NULL as the UserRights
    > > parameter, which is supposed to return ALL accounts, but I get back a list
    > > which has the built-in accounts and a few others (see below), but not one
    > > single normal user account. I just want the accounts for people who can log
    > > on interactively. I'd prefer if there was a fully .NET C# solution but I'll
    > > do Win32 if I have to. Should I be using LsaLookupNames2 instead?
    > >
    > > NT AUTHORITY\SERVICE
    > > BUILTIN\Remote Desktop Users
    > > BUILTIN\Backup Operators
    > > BUILTIN\Users
    > > BUILTIN\Administrators
    > > Justin-Laptop\Guest
    > > Justin-Laptop\SQLServer2005MSSQLUser$Justin-Laptop$SQLEXPRESS
    > > Justin-Laptop\SQLServer2005SQLBrowserUser$Justin-Laptop
    > > NT AUTHORITY\NETWORK SERVICE
    > > NT AUTHORITY\LOCAL SERVICE
    > > Everyone


+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 12-17-2007, 10:53 AM
  2. IE Can't Enumerate User-Added Window Properties with for..in
    By Application Development in forum Javascript
    Replies: 0
    Last Post: 11-25-2007, 08:41 PM
  3. enumerate user permissions
    By Application Development in forum Sharepoint
    Replies: 2
    Last Post: 07-10-2007, 05:53 PM
  4. Configuring user mailboxes or user accounts in Mercury
    By Application Development in forum Pegasus
    Replies: 5
    Last Post: 03-27-2005, 01:55 AM
  5. Making applets work for all user accounts in Windows XP
    By Application Development in forum Java
    Replies: 0
    Last Post: 01-28-2004, 04:19 AM