diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 2d937cb..d574edc 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -290,6 +290,7 @@ namespace OpenHardwareMonitor.GUI { // Make sure the settings are saved when the user logs off Microsoft.Win32.SystemEvents.SessionEnded += delegate { + computer.Close(); SaveConfiguration(); if (runWebServer.Value) server.Quit(); diff --git a/Hardware/KernelDriver.cs b/Hardware/KernelDriver.cs index 5b5501b..6225b0e 100644 --- a/Hardware/KernelDriver.cs +++ b/Hardware/KernelDriver.cs @@ -41,13 +41,13 @@ namespace OpenHardwareMonitor.Hardware { null); if (service == IntPtr.Zero) { - if (Marshal.GetHRForLastWin32Error() == ERROR_SERVICE_EXISTS) - service = NativeMethods.OpenService(manager, id, - ServiceAccessRights.SERVICE_ALL_ACCESS); - else { + if (Marshal.GetHRForLastWin32Error() == ERROR_SERVICE_EXISTS) { + errorMessage = "Service already exists"; + return false; + } else { errorMessage = "CreateService returned the error: " + Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()).Message; - NativeMethods.CloseServiceHandle(manager); + NativeMethods.CloseServiceHandle(manager); return false; } } diff --git a/Hardware/Ring0.cs b/Hardware/Ring0.cs index 155be61..940c0ce 100644 --- a/Hardware/Ring0.cs +++ b/Hardware/Ring0.cs @@ -46,29 +46,29 @@ namespace OpenHardwareMonitor.Hardware { IOControlCode.Access.Read); private static string GetTempFileName() { - - // try to get a file in the temporary folder - try { - return Path.GetTempFileName(); - } catch (IOException) { - // some I/O exception - } - catch (UnauthorizedAccessException) { - // we do not have the right to create a file in the temp folder - } - catch (NotSupportedException) { - // invalid path format of the TMP system environment variable - } - - // if this failed, we try to create one in the application folder + + // try to create one in the application folder string fileName = Path.ChangeExtension( - Assembly.GetExecutingAssembly().Location, ".sys"); + Assembly.GetEntryAssembly().Location, ".sys"); try { using (FileStream stream = File.Create(fileName)) { return fileName; } } catch (IOException) { } catch (UnauthorizedAccessException) { } + + // if this failed, try to get a file in the temporary folder + try { + return Path.GetTempFileName(); + } catch (IOException) { + // some I/O exception + } + catch (UnauthorizedAccessException) { + // we do not have the right to create a file in the temp folder + } + catch (NotSupportedException) { + // invalid path format of the TMP system environment variable + } return null; } diff --git a/Properties/AssemblyVersion.cs b/Properties/AssemblyVersion.cs index 28c56fd..75737a6 100644 --- a/Properties/AssemblyVersion.cs +++ b/Properties/AssemblyVersion.cs @@ -10,5 +10,5 @@ using System.Reflection; -[assembly: AssemblyVersion("0.5.1.2")] -[assembly: AssemblyInformationalVersion("0.5.1.2 Alpha")] \ No newline at end of file +[assembly: AssemblyVersion("0.5.1.4")] +[assembly: AssemblyInformationalVersion("0.5.1.4 Alpha")] \ No newline at end of file