简体   繁体   中英

What would Environment.UserName return when used in a Windows Service

If I'm not wrong, window services are started when the computer boots. So, if I try to get Environment.UserName before a user has logged in, will it return something or will it throw an exception? If it is the former, what would it return?

Anything running in Windows is executing as some account, and services are no different -- which account in specific depends on how the service was started and configured.

See here for more info: https://docs.microsoft.com/en-us/windows/win32/services/service-user-accounts

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