コード例 #1
0
ファイル: SetupHelper.cs プロジェクト: yytitx/HackBGRT
 /**
  * The Main program.
  *
  * @param args The arguments.
  */
 public static void Main(string[] args)
 {
             #if GIT_DESCRIBE
     Console.WriteLine("HackBGRT installer version: {0}", GIT_DESCRIBE.data);
             #else
     Console.WriteLine("HackBGRT installer version: unknown; not an official release?");
             #endif
     var self = Assembly.GetExecutingAssembly().Location;
     try {
         // Relaunch as admin, if needed.
         var id        = WindowsIdentity.GetCurrent();
         var principal = new WindowsPrincipal(id);
         var admin     = WindowsBuiltInRole.Administrator;
         if (!principal.IsInRole(admin) && !args.Contains("no-elevate"))
         {
             ProcessStartInfo startInfo = new ProcessStartInfo(self);
             startInfo.Arguments       = "no-elevate";
             startInfo.Verb            = "runas";
             startInfo.UseShellExecute = true;
             Process p = Process.Start(startInfo);
             p.WaitForExit();
             Environment.ExitCode = p.ExitCode;
             return;
         }
         Efi.EnablePrivilege();
     } catch {
         Console.WriteLine("This installer needs to be run as administrator!");
         Console.WriteLine("Press any key to quit.");
         Console.ReadKey();
         Environment.ExitCode = 1;
         return;
     }
     Setup.RunSetup(Path.GetDirectoryName(self));
 }
コード例 #2
0
    /**
     * Check Secure Boot status and inform the user.
     */
    public static void HandleSecureBoot()
    {
        int secureBoot = Efi.GetSecureBootStatus();

        if (secureBoot == 0)
        {
            Console.WriteLine("Secure Boot is disabled, good!");
        }
        else
        {
            if (secureBoot == 1)
            {
                Console.WriteLine("Secure Boot is probably enabled.");
            }
            else
            {
                Console.WriteLine("Secure Boot status could not be determined.");
            }
            Console.WriteLine("It's very important to disable Secure Boot before installing.");
            Console.WriteLine("Otherwise your machine may become unbootable.");
            Console.WriteLine("Choose action (press a key):");
            bool canBootToFW = Efi.CanBootToFW();
            if (canBootToFW)
            {
                Console.WriteLine(" S = Enter EFI Setup to disable Secure Boot manually; requires reboot!");
            }
            Console.WriteLine(" I = Install anyway; THIS MAY BE DANGEROUS!");
            Console.WriteLine(" C = Cancel");
            var k = Console.ReadKey().Key;
            Console.WriteLine();
            if (k == ConsoleKey.I)
            {
                Console.WriteLine("Continuing. THIS MAY BE DANGEROUS!");
            }
            else if (canBootToFW && k == ConsoleKey.S)
            {
                Efi.SetBootToFW();
                Console.WriteLine();
                Console.WriteLine("Reboot your computer. You will then automatically enter the UEFI setup.");
                Console.WriteLine("Find and disable Secure Boot, then save and exit, then run this installer.");
                Console.WriteLine("Press R to reboot now, other key to exit.");
                var k2 = Console.ReadKey().Key;
                Console.WriteLine();
                if (k2 == ConsoleKey.R)
                {
                    StartProcess("shutdown", "-f -r -t 1");
                }
                Environment.Exit(0);
                throw new ExitSetup(0);
            }
            else
            {
                Console.WriteLine("Aborting because of Secure Boot.");
                throw new ExitSetup(1);
            }
        }
    }