简体   繁体   English

检测应用程序是否在系统帐户下运行?

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

相关问题 在权限较低的帐户下运行的应用程序是否可以启动在管理帐户下执行另一个应用程序的进程? - Can an application running under a less privileged account start a process executing another application under an administrative account? 在系统帐户下运行 Windows 计划任务时出错 - Error running a Windows Scheduled Task under System Account 如何在系统 Windows 用户帐户下启动控制台应用程序? - How to start a Console App as running under the System Windows user account? 从应用程序检测系统文件运行过程 - detect a system file running process from an application 如何在系统帐户下获取所有用户应用程序数据文件夹? - How to get all users application data folders under system account? 如何检测哪个Windows帐户正在运行.net应用程序? - How to detect which Windows account is running a .net application? 注销时,为什么应用程序在Windows上作为系统帐户运行 - Why does an application running as the system account on windows when logging off 在带有“本地系统帐户”的“ Windows服务”下运行时,.NET Windows 7截屏不起作用 - .NET Windows 7 take screenshot not working when running under 'Windows Service' with 'Local System Account' 如何发现运行ASP.Net应用程序的IIS帐户? - How do I discover the IIS account under which an ASP.Net application is running? 从系统帐户下的服务启动过程 - Launching process from service under system account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM