Using C# as a programming vehicle and under windows 10, and using MSVC-2017. I am not using, nor interested in using SQL or Databases. But in this request for help, I'm looking to retrieve ALL username info. Not just the current one. But with further books, I can retrieve more info on my own. I have looked on this site and found some - but they dealt with sql and databases, which I'm really interested in right now. I've also found some that the code does not work and/or also works with SQL and databases. Furthermore, what C# advanced book(s) tells about these nice services that you don't normally know and learn. I'm still learning C# my own. Any help, Thanks, I'd appreciate it.
Asked
Active
Viewed 106 times
-1
-
1This site is about helping people solve problems or bugs in their code. That does not really apply to your question. – Johan Donne Dec 15 '20 at 06:04
-
You might use a WMI query on [Win32_UserAccount](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-useraccount) – Klaus Gütter Dec 15 '20 at 06:10
-
I already gave you the link to the WMI class. You will find lots of examples on how to query WMI using C#. I suggest that you try it yourself and come back if you have a specific problem. I'm not going to write the complete code for you. – Klaus Gütter Dec 15 '20 at 07:15
1 Answers
0
If you are using c# with asp.net the the following function will return the userList
using System.DirectoryServices;
public List<string> GetUserList()
{
List<string> userList = new List<string>();
var path = string.Format("WinNT://{0},computer", Environment.MachineName);
using (var computerEntry = new DirectoryEntry(path))
{
foreach (DirectoryEntry childEntry in computerEntry.Children)
{
if (childEntry.SchemaClassName == "User")
{
userList.Add(childEntry.Name); // you can find all other additional information
// of a user in the childEntry reference
}
}
}
return userList;
}

Raihan Ridoy
- 678
- 8
- 18