9

I have a little application I build that monitors tickets submitted. It basically just sits there in the corner and notifies when new tickets arrive. I need to get the persons username who is logged into the computer to pull their tickets.

I tried searching, but I think I'm using the wrong terminology as I couldn't really find anything.

Jhorra
  • 6,233
  • 21
  • 69
  • 123
  • You have a WPF application that depends on the user's credentials to alert when a ticket is received? – IAbstract May 21 '10 at 21:22
  • Sure, it's got a timer so every so often it checks the database for new tickets. – Jhorra May 21 '10 at 21:41
  • The solutions below from @SLaks and @"Jouke van der Maas" work well to get the username that launched the executing process, which isn't necessarily the same as the logged in (or interactive) user (e.g., a system service). If you need the latter, see [this question](http://stackoverflow.com/questions/5218778/how-to-get-currently-logged-username-from-windows-service-in-net). – Michael Repucci Feb 10 '15 at 22:03

2 Answers2

22

You're looking for the Environment.UserName property.

You may also be looking for the Environment.UserDomainName property.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
5

Try System.Security.Principal.WindowsIdentity.GetCurrent().Name

Jouke van der Maas
  • 4,117
  • 2
  • 28
  • 35