有没有办法检查.NET Standard 2.0中的Sudo / Administrator?

时间:2018-03-29 21:55:11

标签: c# .net .net-standard .net-standard-2.0

在.NET Framework中,我会检查类似的内容:

(new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator)

我现在开始使用.NET标准2.0来定位项目,该项目中没有WindowsPrincipalWindowsIdentity - 看起来似乎是这样。

检查进程是否使用Sudo / Administrator运行的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

您可以从.NET Standard 2.0库中引用其他提供.NET Standard资产的软件包。这意味着您应该能够添加对@JeroenMostert提及的包的引用:System.Security.Principal.Windows并且您应该能够使用它。

需要注意的是,代码只能在Windows上运行。如果您从.NET Core 2.0应用程序中使用它并在Windows上运行它,代码应该可以工作。

如果没有,请在此处提出问题:https://github.com/dotnet/corefx/issues/new