hexagon-oss / openhardwaremonitor

Open Hardware Monitor - a tool for monitoring hardware performance. Includes support for various temperature sensors, disk I/O ratings and power consumption.
Mozilla Public License 2.0
188 stars 21 forks source link

There is an issue causing program to crash on start due to startup handling #49

Closed easymoney322 closed 1 year ago

easymoney322 commented 1 year ago

This code in OpenHardwareMonitor/GUI/StartupManager.cs:

    private void DeleteSchedulerTask() {
      ITaskFolder root = scheduler.GetFolder("\\");
      try {
        ITaskFolder folder = root.GetFolder("Open Hardware Monitor");
        folder.DeleteTask("Startup", 0);
      } catch (IOException) { }
      try {
        root.DeleteFolder("Open Hardware Monitor", 0);
      } catch (IOException) { }
    }

implies there is a "Startup" task, tries to remove it and then tries to remove the folder aswell.

However, if there are any other startup tasks in the folder, it will fail to delete the folder, will crash the app with an error error:

Application: OpenHardwareMonitor.exe
CoreCLR Version: 6.0.2023.32017
.NET Version: 6.0.20
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.COMException (0x80070091): Папка не пуста. (0x80070091)
   at OpenHardwareMonitor.TaskScheduler.ITaskFolder.DeleteFolder(String subFolderName, Int32 flags)
   at OpenHardwareMonitor.GUI.StartupManager.DeleteSchedulerTask() in C:\projects\openhardwaremonitor\OpenHardwareMonitor\GUI\StartupManager.cs:line 232
   at OpenHardwareMonitor.GUI.StartupManager.ConfigureAutoStartup(Boolean enable, Boolean atBootup) in C:\projects\openhardwaremonitor\OpenHardwareMonitor\GUI\StartupManager.cs:line 291
   at OpenHardwareMonitor.GUI.MainForm.<.ctor>b__42_9(Object sender, EventArgs e) in C:\projects\openhardwaremonitor\OpenHardwareMonitor\GUI\MainForm.cs:line 284
   at OpenHardwareMonitor.GUI.UserOption.add_Changed(EventHandler value) in C:\projects\openhardwaremonitor\OpenHardwareMonitor\GUI\UserOption.cs:line 98
   at OpenHardwareMonitor.GUI.MainForm..ctor() in C:\projects\openhardwaremonitor\OpenHardwareMonitor\GUI\MainForm.cs:line 278
   at OpenHardwareMonitor.Program.Main(String[] args) in C:\projects\openhardwaremonitor\OpenHardwareMonitor\Program.cs:line 52

The exception, however, isn't handled, as you can see, as it's COMException. "Папка не пуста" == Folder is not empty.

This happened to me on the first launch of the app, since I've run custom tasks with an official version prior to installation of this one.

I'd also suggest to avoid even trying to delete this task scheduler folder, since user may try to put their own scripts here, and deleting them would be wrong.