Wednesday, January 31, 2018

c# - How can I get a pc's user name?




I'm trying the get the user's name [ex) admin, John, Lucy, etc.] so I can store it to a string and create a file path to save files in my application. I have absolutely no idea how to do this. I tried using the Microsoft.AspNet.Identity; namespace but that didn't help me any, as the UserManager class item is templated to take a User, which is what I'm trying to find in the first place. I'm honestly just walking through the forest at night right now. Can't see and no idea where to go. Any help would be awesome!! Thanks


Answer



Try this to get the username of the currently logged on user:



string username = Environment.UserName;



Microsoft Docs



This is in the system namespace, so there's no need to use Windows Identity.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...