From c2f1a517259a165118b51dd100506a64bba02515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Sun, 23 Sep 2012 18:37:43 +0000 Subject: [PATCH] Fixed Issue 387. The new implementation does not try to start a ring 0 driver that already exists, but could not be opened. It tries to delete the driver and install it new. The driver is now stored temporarily in the application folder. The driver is not correctly removed on system shutdown. --- GUI/MainForm.cs | 1 + Hardware/KernelDriver.cs | 10 +++++----- Hardware/Ring0.cs | 32 ++++++++++++++++---------------- Properties/AssemblyVersion.cs | 4 ++-- 4 files changed, 24 insertions(+), 23 deletions(-) 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