static string GetPlainTextReport(CommandLineOptions.OptionsBase options)
        {
            Computer computer = computerHardware.ComputerDiagnostics(options);
            string   Result   = computer.GetReport();

            computer.Close();
            return(Result);
        }
        static private int InitBaseOptionsAndEnforceAdminPrivileges(CommandLineOptions.OptionsBase options)
        {
            WaitOnExitForSeconds  = options.WaitOnExitForSeconds;
            WaitOnExitForEnterKey = options.WaitOnExitForEnterKey;
            VerboseMode           = options.VerboseMode;

            //Console.Out.WriteLine("Time to attach the debugger . . . ");
            //Console.ReadLine();

            //prepare log file

            if (!string.IsNullOrEmpty(options.LogFile) && System.IO.File.Exists(options.LogFile))
            {
                Utility.WriteLogMessage("--------------------------------------------------------------------------------------------", options, false);
            }
            if (!string.IsNullOrEmpty(options.LogFile))
            {
                Utility.WriteLogMessage("Application started on " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), options, false);
            }
            if (!Utility.IsUserAdministrator())
            {
                Utility.WriteLogMessage("Application requires administration privileges, restart of process as administrator required", options, false);
            }

            int ExitCodeOfAdminMode = Utility.EnforceAppIsRunAsAdmin();

            if (ExitCodeOfAdminMode == -2)
            {
                Utility.WriteLogMessage("ERROR: Administrator permission required (" + ExitCodeOfAdminMode.ToString() + ")", options, true);
                return(9);
            }
            else if (ExitCodeOfAdminMode > 0)
            {
                //code already executed successfully in separate application process with successfully requested administration privileges
                return(ExitCodeOfAdminMode);
            }
            else if (ExitCodeOfAdminMode == -1)
            {
                //regular code execution should take place in following steps - we are running with adminitration privileges
                if (!string.IsNullOrEmpty(options.LogFile))
                {
                    Utility.WriteLogMessage("Application started with administration privileges", options, false);
                }
                return(ExitCodeOfAdminMode);
            }
            else if (ExitCodeOfAdminMode == 0)
            {
                //Succcess! :-)
                return(ExitCodeOfAdminMode);
            }
            else
            {
                //window close button or system terminates (e.g. logoff event) can cause negative exit codes - just log it as warning
                Utility.WriteLogMessage("WARNING: exit code of process with administration privileges was " + ExitCodeOfAdminMode.ToString() + ", possibly caused by a close event by system or user", null, false);
                return(ExitCodeOfAdminMode);
            }
        }
예제 #3
0
 /// <summary>
 /// Log a message to console output, console errors or a log file
 /// </summary>
 /// <param name="message"></param>
 /// <param name="options"></param>
 /// <param name="isError"></param>
 static public void WriteLogMessage(Exception exception, CommandLineOptions.OptionsBase options)
 {
     if ((options != null) && options.VerboseMode)
     {
         WriteLogMessage("ERROR: " + exception.ToString(), options, true);
     }
     else
     {
         WriteLogMessage("ERROR: " + exception.Message, options, true);
     }
 }
예제 #4
0
 /// <summary>
 /// Log a message to console output, console errors or a log file
 /// </summary>
 /// <param name="message"></param>
 /// <param name="options"></param>
 /// <param name="isError"></param>
 /// <param name="logToConsoleAndFileIfAvailable"></param>
 static public void WriteLogMessage(string message, CommandLineOptions.OptionsBase options, bool isError, bool logToConsoleAndFileIfAvailable)
 {
     if (options == null)
     {
         //no options parsed successfully
         Console.Out.WriteLine(message);
     }
     else if (string.IsNullOrEmpty(options.LogFile))
     {
         //no log file
         if (isError)
         {
             Console.Error.WriteLine(message);
         }
         else
         {
             Console.Out.WriteLine(message);
         }
     }
     else
     {
         //use log file
         try
         {
             System.IO.File.AppendAllText(options.LogFile, message + System.Environment.NewLine);
             if (logToConsoleAndFileIfAvailable)
             {
                 if (isError)
                 {
                     Console.Error.WriteLine(message);
                 }
                 else
                 {
                     Console.Out.WriteLine(message);
                 }
             }
         }
         catch (Exception ex)
         {
             Console.Error.WriteLine("ERROR WRITING TO LOG FILE: " + ex.Message);
         }
     }
 }
예제 #5
0
        public Computer ComputerDiagnostics(CommandLineOptions.OptionsBase options)
        {
            if (computer != null)
            {
                computer.Close();
            }

            computer = new Computer();

            computer.CPUEnabled           = !options.IgnoreMonitorCPU;
            computer.FanControllerEnabled = !options.IgnoreMonitorFanController;
            computer.GPUEnabled           = !options.IgnoreMonitorGPU;
            computer.HDDEnabled           = !options.IgnoreMonitorHDD;
            computer.MainboardEnabled     = !options.IgnoreMonitorMainboard;
            computer.RAMEnabled           = !options.IgnoreMonitorRAM;
            computer.NetworkEnabled       = !options.IgnoreMonitorNetwork;

            computer.HardwareAdded   += new HardwareEventHandler(HardwareAdded);
            computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);

            // add platform dependent code
            int p = (int)Environment.OSVersion.Platform;

            if ((p == 4) || (p == 128))
            {
                // Unix
            }
            else
            {
                // Windows
                // not sure if really required: gadget = new OpenHardwareMonitor.GUI.SensorGadget(computer, settings, unitManager);
                wmiProvider = new OpenHardwareMonitor.WMI.WmiProvider(computer);
            }

            computer.Open();

            computer.Accept(this.updateVisitor);

            return(computer);
        }
예제 #6
0
 /// <summary>
 /// Log a message to console output, console errors or a log file
 /// </summary>
 /// <param name="message"></param>
 /// <param name="options"></param>
 /// <param name="isError"></param>
 static public void WriteLogMessage(string message, CommandLineOptions.OptionsBase options, bool isError)
 {
     WriteLogMessage(message, options, isError, false);
 }