简体   繁体   中英

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.

尝试在具有足够权限来调用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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM