Getting a List of User Profiles on a Computer in C++ Win32

Getting a list of user profiles on a computer in C++ Win32

Before going the undocumented route like flokra suggests, I would try NetUserEnum() or NetQueryDisplayInformation()

If you want to go into undocumented land, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList has a (incomplete) list of accounts (It's missing special accounts like ASPNET, HelpAssistant and SUPPORT_xxxx) It also has the path to the profile folder, which is a lot safer than using %ALLUSERSPROFILE%\..\ but why use it when there is GetProfilesDirectory()

How do I get a list of domain user accounts with win32 api?

Look into the LDAP API. This will let you query the LDAP server which will have a list of the user accounts.

List of Windows real users using Win32 API

As you said, the last step probably is just filter the users which belong to Administrators or Users group.

Try the method NetUserGetLocalGroups for enumerating the groups an user belongs to.

how to get the user accounts and buit in security principles in windows

You can do this via WSH. Here is an example in JavaScript: http://www.winscripter.com/WSH/ADSI/56.aspx

and a sample in C#: http://www.geekzone.co.nz/chakkaradeep/3938

I found several answers on BING by searching win32 list user accounts

And finally a sample from Microsoft: http://gallery.technet.microsoft.com/ScriptCenter/en-us/827623f5-eb55-4035-8f57-25c4afb444cd

How can I get a list of users from active directory?

If you are new to Active Directory, I suggest you should understand how Active Directory stores data first.

Active Directory is actually a LDAP server. Objects stored in LDAP server are stored hierarchically. It's very similar to you store your files in your file system. That's why it got the name Directory server and Active Directory

The containers and objects on Active Directory can be specified by a distinguished name. The distinguished name is like this CN=SomeName,CN=SomeDirectory,DC=yourdomain,DC=com. Like a traditional relational database, you can run query against a LDAP server. It's called LDAP query.

There are a number of ways to run a LDAP query in .NET. You can use DirectorySearcher from System.DirectoryServices or SearchRequest from System.DirectoryServices.Protocol.

For your question, since you are asking to find user principal object specifically, I think the most intuitive way is to use PrincipalSearcher from System.DirectoryServices.AccountManagement. You can easily find a lot of different examples from google. Here is a sample that is doing exactly what you are asking for.

using (var context = new PrincipalContext(ContextType.Domain, "yourdomain.com"))
{
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
foreach (var result in searcher.FindAll())
{
DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
Console.WriteLine("First Name: " + de.Properties["givenName"].Value);
Console.WriteLine("Last Name : " + de.Properties["sn"].Value);
Console.WriteLine("SAM account name : " + de.Properties["samAccountName"].Value);
Console.WriteLine("User principal name: " + de.Properties["userPrincipalName"].Value);
Console.WriteLine();
}
}
}
Console.ReadLine();

Note that on the AD user object, there are a number of attributes. In particular, givenName will give you the First Name and sn will give you the Last Name. About the user name. I think you meant the user logon name. Note that there are two logon names on AD user object. One is samAccountName, which is also known as pre-Windows 2000 user logon name. userPrincipalName is generally used after Windows 2000.

Check windows user existence without linking additional dlls and throwing exceptions in c#

You should check agains the active directory, to be sure wether a user really exists. When you only check the local computer, only users which has logged in to the computer will be returned.

If you don't want to use an additional assembly (which will be recommended) you can use the DllImport to use Win32 for checking wether the user exists. But this way is not very nice.

If you want to read about this, look at: Getting a list of user profiles on a computer in C++ Win32



Related Topics



Leave a reply



Submit