Пример #1
0
        private void tabLogonHistory_Selected(object sender, RoutedEventArgs e)
        {
            // Elevate the process if targeting local computer and is not run as administrator.
            if (RemoteLogonSession.ComputerName == Environment.MachineName && !ElevationHelper.IsRunAsAdmin())
            {
                // Launch itself as administrator
                ProcessStartInfo proc = new ProcessStartInfo();
                proc.UseShellExecute  = true;
                proc.WorkingDirectory = Environment.CurrentDirectory;
                proc.FileName         = System.Reflection.Assembly.GetExecutingAssembly().Location;
                proc.Verb             = "runas";
                proc.Arguments        = "Elevate LogonHistory";

                try
                {
                    Process.Start(proc);
                }
                catch
                {
                    // The user refused the elevation.
                    // Do nothing and return directly ...
                    gridHistoryLoading.Visibility = Visibility.Collapsed;
                    gridNoHistory.Visibility      = Visibility.Collapsed;
                    tbHistoryError.Text           = "Access denied.";
                    gridHistoryError.Visibility   = Visibility.Visible;
                    return;
                }

                Application.Current.Shutdown();
            }
            else
            {
                // Setup a background thread.
                var bgWorker = new BackgroundWorker();
                bgWorker.DoWork             += new DoWorkEventHandler(bgThread_GetLogonHistory);
                bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgThread_GetLogonHistoryCompleted);

                // Display overlay window indicating work is being performed.
                gridNoHistory.Visibility      = Visibility.Collapsed;
                gridError.Visibility          = Visibility.Collapsed;
                gridHistoryLoading.Visibility = Visibility.Visible;

                // Retrieve event log in a new background thread.
                bgWorker.RunWorkerAsync();
            }
        }
Пример #2
0
        private void MenuButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtTargetComputer.Text))
            {
                return;
            }

            var selectedButton = sender as Button;

            SetMenuColors(selectedButton);
            SelectedItem.Text            = selectedButton.Content.ToString();
            SelectedTarget.Text          = txtTargetComputer.Text;
            SelectedTarget.Visibility    = Visibility.Visible;
            txtTargetComputer.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#000000"));
            switch (SelectedItem.Text)
            {
            case "System Info":
                contentControl.Content = new SystemInfoView(txtTargetComputer.Text.Trim());
                break;

            case "Processes":
                // Elevate the process if targeting local computer and is not run as administrator.
                if (txtTargetComputer.Text == Environment.MachineName && !ElevationHelper.IsRunAsAdmin())
                {
                    // Launch itself as administrator
                    ProcessStartInfo proc = new ProcessStartInfo();
                    proc.UseShellExecute  = true;
                    proc.WorkingDirectory = Environment.CurrentDirectory;
                    proc.FileName         = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    proc.Verb             = "runas";
                    proc.Arguments        = "Elevate Processes";

                    try
                    {
                        Process.Start(proc);
                    }
                    catch
                    {
                        // The user refused the elevation.
                        // Do nothing and return directly ...
                        contentControl.Content = new ProcessesView(txtTargetComputer.Text.Trim());
                        break;
                    }

                    Application.Current.Shutdown();
                }
                else
                {
                    contentControl.Content = new ProcessesView(txtTargetComputer.Text.Trim());
                }
                break;

            case "Services":
                contentControl.Content = new ServicesView(txtTargetComputer.Text.Trim());
                break;

            case "Networking":
                contentControl.Content = new NetworkingView(txtTargetComputer.Text.Trim());
                break;

            case "Storage":
                contentControl.Content = new StorageView(txtTargetComputer.Text.Trim());
                break;

            case "Applications":
                contentControl.Content = new ApplicationsView(txtTargetComputer.Text.Trim());
                break;

            case "Updates":
                contentControl.Content = new UpdatesView(txtTargetComputer.Text.Trim());
                break;

            case "Users":
                contentControl.Content = new LogonSessionsView(txtTargetComputer.Text.Trim());
                break;

            case "Tasks":
                SelectedTarget.Visibility = Visibility.Collapsed;
                contentControl.Content    = new TasksView();
                break;

            case "Bulk Query":
                SelectedTarget.Visibility    = Visibility.Collapsed;
                txtTargetComputer.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#999"));
                contentControl.Content       = _BulkQueryView;
                break;

            default:
                MessageBox.Show("Button not defined.");
                break;
            }
        }