Exemple #1
0
        /// <summary>
        /// Handles the Startup event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="StartupEventArgs"/> instance containing the event data.</param>
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // force software to run as administrator

            bool isElevated;
            WindowsIdentity identity = WindowsIdentity.GetCurrent();
            WindowsPrincipal principal = new WindowsPrincipal(identity);
            isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);
            if (!isElevated)
            {
                ProcessStartInfo proc = new ProcessStartInfo();
                proc.UseShellExecute = true;

                String exePath = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;
                proc.WorkingDirectory = System.IO.Path.GetDirectoryName(exePath);
                proc.FileName = exePath;
                proc.Verb = "runas";

                try
                {
                    Process.Start(proc);
                }
                catch
                {
                    // The user refused the elevation.
                    // Do nothing and return directly ...
                    return;
                }

                Environment.Exit(0);
            }
            else
            {
                // show log window
                if (ApplicationSettings.ShowLogs)
                {
                    winLog winLog = new winLog();
                    winLog.LogsSource = Log.LogCollections;
                    winLog.Show();
                }

                new Log("Starting Software");

                var mainWin = new HDD_Searcher.MainWindow();
                mainWin.Show();
            }
        }
 /// <summary>
 /// Handles the Click event of the btnShowlog control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
 private void btnShowlog_Click(object sender, RoutedEventArgs e)
 {
     winLog log = new winLog();
     log.LogsSource = Log.LogCollections;
     log.Show();
 }