user1013552
user1013552

Reputation: 313

Receiving name of user launching application

How to get User name which is launching my app? Code:

Environment.UserName

returns current logged user, but I want name of the user which is launching app(for example through run as administrator).

Upvotes: 0

Views: 356

Answers (2)

competent_tech
competent_tech

Reputation: 44971

If I understand your question, you want the actual user that the application is running as (i.e. administrator) and not the logged in user.

In this case, you want to get the Name from the current WindowsIdentity:

var sCurrentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

Upvotes: 1

escargot agile
escargot agile

Reputation: 22389

Even when you run a program as administrator, you're running it as the same user (if the user has administrator rights).

Environment.UserName does in fact return the name of the user who runs the applications. Look in the Task Manager and you'll see it.

Upvotes: 4

Related Questions