예제 #1
0
        private void RebootButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (!(ListBox.SelectedItem is BootSection selected))
            {
                return;
            }

            BootNextInterface.BootTo(BootNextPath, selected.Key);

            // Ugly reboot hack, thanks MS
            var w32 = new ManagementClass("Win32_OperatingSystem");

            w32.Scope.Options.EnablePrivileges = true;

            foreach (var o in w32.GetInstances())
            {
                var obj      = (ManagementObject)o;
                var inParams = obj.GetMethodParameters("Win32Shutdown");
                inParams["Flags"]    = 2;
                inParams["Reserved"] = 0;

                var outParams = obj.InvokeMethod("Win32Shutdown", inParams, null) !;
                var result    = Convert.ToInt32(outParams["returnValue"]);
                if (result != 0)
                {
                    throw new Win32Exception(result);
                }
            }
        }
예제 #2
0
        private void InstallButton_OnClick(object sender, RoutedEventArgs e)
        {
            var selected = (Partition?)AllEfisList.SelectedItem;

            if (selected == null)
            {
                return;
            }

            var result = MessageBox.Show("Installing BootNext will reset any BootNext configuration on " +
                                         "that device to default. Are you sure you want to continue?",
                                         "BootNext", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.No)
            {
                return;
            }

            try {
                BootNextInterface.InstallTo(selected);
            }
            catch (Exception ex)
            {
                BootMessageBox.Show("Installation failed", $"Could not install BootNext: {ex}");
                return;
            }

            // set target
            Settings.Default.PreferredEFI = selected.Guid;
            Settings.Default.Save();
            ReloadInstalled();

            var bootNextDir = DiskScanner.GetBootNextDir(selected.GetDriveLetter() !);

            BootMessageBox.Show("Installation successful",
                                "Installation of BootNext is now finished. In order to use BootNext, " +
                                "you need to add it to your boot order manually.\n\n" +
                                "In order to configure BootNext, the installation folder will now be opened in an Explorer++ window.");

            var          dir          = Path.GetDirectoryName(Assembly.GetEntryAssembly() !.Location) !;
            const string explorerPath = @"Resources\Explorer++.exe";

            Process.Start(Path.Combine(dir, explorerPath), bootNextDir);
        }