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.
Try running the service under an account that has enough privileges to call GetOwner().
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.
精彩评论