I want to check whether a user exists on a local machine in a C# program. The only two ways I've found are the following:
I don't want to use them both: Not the first because I don't want to add reference for a single check and not the second because it is not an exceptional situation, in some cases the user does not exists and it is normal.
So, I have two a question:
1) Why should we use active directory in the second case, why don't we just look up the user directory in the Users directory?
2) Are there any alternative ways to do this?
Upd: Thanks, BendEg, Dan J, now I have only one question
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