开发者

how to get under which username a process running

开发者 https://www.devze.com 2023-02-15 02:22 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消