Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

38 строки
1.2 KiB

  1. using System;
  2. using System.Security.Principal;
  3. using System.Windows.Forms;
  4. namespace ThunderboltTimeSync {
  5. static class Program {
  6. /// <summary>
  7. /// Checks if the application is currently running with administrator privileges.
  8. /// </summary>
  9. /// <returns>True if the application is running with administrator privileges, false otherwise.</returns>
  10. private static bool IsRunningAsAdministrator() {
  11. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  12. WindowsPrincipal principal = new WindowsPrincipal(identity);
  13. return principal.IsInRole(WindowsBuiltInRole.Administrator);
  14. }
  15. /// <summary>
  16. /// The main entry point for the application.
  17. /// </summary>
  18. [STAThread]
  19. static void Main() {
  20. Application.EnableVisualStyles();
  21. Application.SetCompatibleTextRenderingDefault(false);
  22. if (!IsRunningAsAdministrator()) {
  23. MessageBox.Show(
  24. "This application must be run with administrative privileges. Without administrative privileges, the system time cannot be set.\n\nPlease restart the application as administrator.",
  25. "Administrative Privileges Required",
  26. MessageBoxButtons.OK,
  27. MessageBoxIcon.Error
  28. );
  29. } else {
  30. Application.Run(new FormMain());
  31. }
  32. }
  33. }
  34. }