[英]What would Environment.UserName return when used in a Windows Service
If I'm not wrong, window services are started when the computer boots.如果我没记错的话,window 服务是在计算机启动时启动的。 So, if I try to get
Environment.UserName
before a user has logged in, will it return something or will it throw an exception?所以,如果我在用户登录之前尝试获取
Environment.UserName
,它会返回一些东西还是会抛出异常? 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.在 Windows 中运行的任何东西都作为某个帐户执行,服务也不例外——具体哪个帐户取决于服务的启动和配置方式。
See here for more info: https://docs.microsoft.com/en-us/windows/win32/services/service-user-accounts请参阅此处了解更多信息: https://docs.microsoft.com/en-us/windows/win32/services/service-user-accounts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.