Geoff Overfield Geoff Overfield - 1 year ago 83
C# Question

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

namespace but that didn't help me any, as the
class item is templated to take a
, 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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download