Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可能可以使用Environment.UserName它并将其与“系统”进行比较以查看它是否匹配,但这似乎很老套,我不确定它在非英语环境中如何工作。关于如何检查当前可执行文件是否作为系统帐户运行的任何其他建议?
Environment.UserName
这应该这样做:
bool isSystem; using (var identity = System.Security.Principal.WindowsIdentity.GetCurrent()) { isSystem = identity.IsSystem; }
切勿比较帐户名称。在本地化操作系统上,将用户名与“系统”进行比较确实会失败。