# HG changeset patch # User moel.mich # Date 1305476430 0 # Node ID fb88cac4a9aa05ae4090f9e13214a1158c2264b6 # Parent a2793a38aac0cd4331e992f36aed097ef7947785 Fixed Issue 218. diff -r a2793a38aac0 -r fb88cac4a9aa Hardware/Ring0.cs --- a/Hardware/Ring0.cs Sun May 15 16:00:22 2011 +0000 +++ b/Hardware/Ring0.cs Sun May 15 16:20:30 2011 +0000 @@ -71,6 +71,27 @@ IOCTL_OLS_READ_MEMORY = new IOControlCode(OLS_TYPE, 0x841, IOControlCode.Access.Read); + private static string GetTempFileName() { + + // try to get a file in the temporary folder + try { + return Path.GetTempFileName(); + } catch (IOException) { } + catch (UnauthorizedAccessException) { } + + // if this failed, we try to create one in the application folder + string fileName = Path.ChangeExtension( + Assembly.GetExecutingAssembly().Location, ".sys"); + try { + using (FileStream stream = File.Create(fileName)) { + return fileName; + } + } catch (IOException) { } + catch (UnauthorizedAccessException) { } + + return null; + } + private static bool ExtractDriver(string fileName) { string resourceName = "OpenHardwareMonitor.Hardware." + (IntPtr.Size == 4 ? "WinRing0.sys" : "WinRing0x64.sys"); @@ -118,8 +139,8 @@ // driver is not loaded, try to reinstall and open driver.Delete(); - fileName = Path.GetTempFileName(); - if (ExtractDriver(fileName)) { + fileName = GetTempFileName(); + if (fileName != null && ExtractDriver(fileName)) { if (driver.Install(fileName)) { driver.Open(); @@ -128,17 +149,15 @@ report.AppendLine("Status: Opening driver failed"); } } else { - report.AppendLine("Status: Installing driver \"" + - fileName + "\" failed" + + report.AppendLine("Status: Installing driver \"" + + fileName + "\" failed" + (File.Exists(fileName) ? " and file exists" : "")); report.AppendLine(); report.Append("Exception: " + Marshal.GetExceptionForHR( Marshal.GetHRForLastWin32Error()).Message); } - } else { - report.AppendLine( - "Status: Extracting driver to \"" + fileName + "\" failed"); + report.AppendLine("Status: Extracting driver failed"); } try {