[英]Detect if application is running under system account?
I could probably use Environment.UserName
and compare that to 'system' to see if it matches, but that seems hacky and I'm not sure how it would work in a non English environment. 我可以使用
Environment.UserName
并将其与'system'进行比较以查看它是否匹配,但这看起来很糟糕,我不确定它在非英语环境中如何工作。 Any other suggestions on how to check if the current executable is running as the system account? 有关如何检查当前可执行文件是否作为系统帐户运行的任何其他建议?
This should do it: 这应该这样做:
bool isSystem;
using (var identity = System.Security.Principal.WindowsIdentity.GetCurrent())
{
isSystem = identity.IsSystem;
}
Never compare the account names. 永远不要比较帐户名称。 Comparing the user name to "System" would indeed fail on a localized OS.
将用户名与“系统”进行比较确实会在本地化操作系统上失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.