예제 #1
0
        private async void MainForm_Load(object sender, EventArgs args)
        {
            isHyperVActive = await HyperV.GetStatus();

            isHyperVRunning = HyperV.GetRunning();

            actionButton.Visible = true;
            actionButton.Focus();

            if (isHyperVActive == true)
            {
                statusLabel.Text      = "Hyper-V is ACTIVE.";
                statusLabel.ForeColor = Color.ForestGreen;
                actionButton.Text     = "Deactivate Hyper-V and restart computer";
                if (isHyperVRunning == false)
                {
                    statusLabel.Text += " However, it is currently NOT running, so a restart may be pending.";
                    justRestart       = true;
                    actionButton.Text = "Restart computer";
                }
            }
            else if (isHyperVActive == false)
            {
                statusLabel.Text      = "Hyper-V is DEACTIVATED.";
                statusLabel.ForeColor = Color.Firebrick;
                actionButton.Text     = "Activate Hyper-V and restart computer";
                if (isHyperVRunning == true)
                {
                    statusLabel.Text += " However, it is currently running, so a restart may be pending.";
                    justRestart       = true;
                    actionButton.Text = "Restart computer";
                }
            }
            else
            {
                statusLabel.Text      = "The current state of Hyper-V is UNKNOWN. The Hyper-V role may not be installed on this computer.";
                statusLabel.ForeColor = SystemColors.WindowText;
                actionButton.Text     = "No action available";
                actionButton.Enabled  = false;
            }
        }
예제 #2
0
        public async Task <ContextMenuStrip> CreateAsync()
        {
            // Add the default menu options.
            var menu = new ContextMenuStrip();


            // Actions.
            isHyperVActive = await HyperV.GetStatus();

            var status = new ToolStripMenuItem();
            var action = new ToolStripMenuItem();

            status.Click += App_Click;
            action.Click += Action_Click;

            status.Font = new Font(status.Font, status.Font.Style | FontStyle.Bold);

            if (isHyperVActive == true)
            {
                status.Text      = "Hyper-V is ACTIVE.";
                status.ForeColor = Color.ForestGreen;
                action.Text      = "Deactivate Hyper-V and restart computer";
            }
            else if (isHyperVActive == false)
            {
                status.Text      = "Hyper-V is DEACTIVATED.";
                status.ForeColor = Color.Firebrick;
                action.Text      = "Activate Hyper-V and restart computer";
            }
            else
            {
                status.Text      = "The current state of Hyper-V is UNKNOWN. The Hyper-V role may not be installed on this computer.";
                status.ForeColor = SystemColors.WindowText;
                action.Text      = "No action available";
                action.Enabled   = false;
            }

            // Add Status.
            menu.Items.Add(status);

            // Separator.
            var sep = new ToolStripSeparator();

            menu.Items.Add(sep);

            // Add Action.
            menu.Items.Add(action);

            // Separator.
            sep = new ToolStripSeparator();
            menu.Items.Add(sep);

            // Exit.
            var item = new ToolStripMenuItem {
                Text = "Exit"
            };

            item.Click += Exit_Click;
            menu.Items.Add(item);

            return(menu);
        }