SecurityHelper.cs 970 B

123456789101112131415161718192021222324252627282930
  1. /* Copyright (C) 2012-2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Security.Principal;
  10. namespace ISCSIConsole
  11. {
  12. public class SecurityHelper
  13. {
  14. public static bool IsAdministrator()
  15. {
  16. WindowsIdentity windowsIdentity = null;
  17. try
  18. {
  19. windowsIdentity = WindowsIdentity.GetCurrent();
  20. }
  21. catch
  22. {
  23. return false;
  24. }
  25. WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity);
  26. return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
  27. }
  28. }
  29. }