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

Time:11-27

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?

CodePudding user response:

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

  • Related