2023-07-03 01:51:09 +08:00
|
|
|
using System.Security.Principal;
|
2022-05-23 00:58:58 +08:00
|
|
|
|
2023-07-03 01:51:09 +08:00
|
|
|
namespace CMM.Library.Helpers;
|
|
|
|
|
|
|
|
|
|
public class UAC
|
2022-05-23 00:58:58 +08:00
|
|
|
{
|
2023-07-03 01:51:09 +08:00
|
|
|
public static void Check()
|
2022-05-23 00:58:58 +08:00
|
|
|
{
|
2023-07-03 01:51:09 +08:00
|
|
|
var identity = WindowsIdentity.GetCurrent();
|
|
|
|
|
var principal = new WindowsPrincipal(identity);
|
|
|
|
|
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
|
|
|
|
|
throw new Exception($"Cannot delete task with your current identity '{identity.Name}' permissions level." +
|
|
|
|
|
"You likely need to run this application 'as administrator' even if you are using an administrator account.");
|
2022-05-23 00:58:58 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|