Question : How can i get currently logged on user detail in .net c# winapp ?

Hi,

I want to use integrated windows AD authentication for my WinForms app.
So when Application starts, user would be determined by the user loggen on to the pc.

If such user exists in application database, it would get selected, if NOT.
New user would be created and all his details filled (like Name, Family name, email, phone, etc).

Can this be done ?

Answer : How can i get currently logged on user detail in .net c# winapp ?

Just tried building that, should really not rush things.  Here is the full thing (working) that outputs my name and where I live (obviously I'm not going to show that output :) )

DirectorySearcher search = new DirectorySearcher(domain);
            search.SearchScope = SearchScope.Subtree;
            search.Filter = "(SAMAccountName=" + Environment.UserName +")";
            search.PropertiesToLoad.Add("cn");
            search.PropertiesToLoad.Add("surname");
            search.PropertiesToLoad.Add("cn"); // Full name
            search.PropertiesToLoad.Add("sn"); // Surname
            search.PropertiesToLoad.Add("givenname"); // First name
            search.PropertiesToLoad.Add("l"); // Location
            search.PropertiesToLoad.Add("c"); // Country
            SearchResult result = search.FindOne();
            if (result != null)
            {
                Console.WriteLine(result.Properties["givenname"][0].ToString() + " " + result.Properties["sn"][0].ToString() + " lives in " + result.Properties["l"][0].ToString());
                //etc
            }
Random Solutions  
 
programming4us programming4us