简体   繁体   English

在 Windows 服务中使用时 Environment.UserName 会返回什么

[英]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.

相关问题 Environment.UserName会在Windows 7,Windows 8.x和Windows 10中返回相同的结果吗? - Will Environment.UserName return the same result in Windows 7, Windows 8.x and Windows 10? Environment.UserName 返回应用程序池名称而不是用户名 - Environment.UserName returning application pool name instead of username 我可以使用 Environment.Username 和 MYSQL 来验证登录吗? - Can I use Environment.Username and MYSQL to verify log in? 将app.config值设置为Environment.UserName - Set app.config value to Environment.UserName Environment.UserName 作为 SYSTEM 而不是用户名返回 - Environment.UserName returning as SYSTEM rather than User's name Environment.UserName 为同一用户(外壳)提供不同的结果:替代/转换? - Environment.UserName gives different results for same user (casing): alternative/transformation? Windows服务:用户登录时获取用户名 - Windows service: Get username when user log on .NET Windows服务用户名 - .NET Windows Service Username 如何使用.NET从多用户环境中的Windows Service获取当前Windows用户名 - How to get current windows username from windows service in multiuser environment using .NET 什么会导致WCF服务返回“对象”类型的对象 - What would cause a WCF service to return an object of type “object”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM