Raj
Raj

Reputation: 4010

how to get under which username a process running

its very irritating, i found a code sample to get username from stackoverflow on how to get under which username a process running and its working fine in console app but not working in windows service. returnVal is 2 and not showing username and domain. Can anyone tell me do i need to change any setting in windows service.

Upvotes: 2

Views: 3919

Answers (2)

Shadow Wizard
Shadow Wizard

Reputation: 66389

I believe that what you're after is simply:

string user = Environment.UserName;

The service itself is running using some system account but you said you're looking for your own account name, meaning the logged in user account.

Upvotes: 0

RQDQ
RQDQ

Reputation: 15569

Try running the service under an account that has enough privileges to call GetOwner().

Upvotes: 1

Related Questions