mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-09-03 15:55:26 +00:00
Added more report output to the kernel driver loading code. Hopefully this helps to find the problems in Issue 253.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
Copyright (C) 2010 Michael Möller <mmoeller@openhardwaremonitor.org>
|
||||
Copyright (C) 2010-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
|
||||
|
||||
*/
|
||||
|
||||
@@ -25,12 +25,14 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public bool Install(string path) {
|
||||
public bool Install(string path, out string errorMessage) {
|
||||
IntPtr manager = NativeMethods.OpenSCManager(null, null,
|
||||
ServiceControlManagerAccessRights.SC_MANAGER_ALL_ACCESS);
|
||||
|
||||
if (manager == IntPtr.Zero)
|
||||
if (manager == IntPtr.Zero) {
|
||||
errorMessage = "OpenSCManager returned zero.";
|
||||
return false;
|
||||
}
|
||||
|
||||
IntPtr service = NativeMethods.CreateService(manager, id, id,
|
||||
ServiceAccessRights.SERVICE_ALL_ACCESS,
|
||||
@@ -42,13 +44,22 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
if (Marshal.GetHRForLastWin32Error() == ERROR_SERVICE_EXISTS)
|
||||
service = NativeMethods.OpenService(manager, id,
|
||||
ServiceAccessRights.SERVICE_ALL_ACCESS);
|
||||
else
|
||||
else {
|
||||
errorMessage = "CreateService returned the error: " +
|
||||
Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()).Message;
|
||||
NativeMethods.CloseServiceHandle(manager);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!NativeMethods.StartService(service, 0, null)) {
|
||||
if (Marshal.GetHRForLastWin32Error() != ERROR_SERVICE_ALREADY_RUNNING)
|
||||
if (Marshal.GetHRForLastWin32Error() != ERROR_SERVICE_ALREADY_RUNNING) {
|
||||
errorMessage = "StartService returned the error: " +
|
||||
Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()).Message;
|
||||
NativeMethods.CloseServiceHandle(service);
|
||||
NativeMethods.CloseServiceHandle(manager);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
NativeMethods.CloseServiceHandle(service);
|
||||
@@ -63,6 +74,7 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
File.SetAccessControl(@"\\.\" + id, fileSecurity);
|
||||
} catch { }
|
||||
|
||||
errorMessage = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -127,7 +127,8 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
|
||||
fileName = GetTempFileName();
|
||||
if (fileName != null && ExtractDriver(fileName)) {
|
||||
if (driver.Install(fileName)) {
|
||||
string installError;
|
||||
if (driver.Install(fileName, out installError)) {
|
||||
driver.Open();
|
||||
|
||||
if (!driver.IsOpen) {
|
||||
@@ -135,10 +136,13 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
report.AppendLine("Status: Opening driver failed after install");
|
||||
}
|
||||
} else {
|
||||
string errorFirstInstall = installError;
|
||||
|
||||
// install failed, try to delete and reinstall
|
||||
driver.Delete();
|
||||
|
||||
if (driver.Install(fileName)) {
|
||||
string errorSecondInstall;
|
||||
if (driver.Install(fileName, out errorSecondInstall)) {
|
||||
driver.Open();
|
||||
|
||||
if (!driver.IsOpen) {
|
||||
@@ -150,9 +154,8 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
report.AppendLine("Status: Installing driver \"" +
|
||||
fileName + "\" failed" +
|
||||
(File.Exists(fileName) ? " and file exists" : ""));
|
||||
report.AppendLine();
|
||||
report.Append("Exception: " + Marshal.GetExceptionForHR(
|
||||
Marshal.GetHRForLastWin32Error()).Message);
|
||||
report.AppendLine("First Exception: " + errorFirstInstall);
|
||||
report.AppendLine("Second Exception: " + errorSecondInstall);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@@ -10,5 +10,5 @@
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyVersion("0.4.0.18")]
|
||||
[assembly: AssemblyInformationalVersion("0.4.0.18 Alpha")]
|
||||
[assembly: AssemblyVersion("0.4.0.19")]
|
||||
[assembly: AssemblyInformationalVersion("0.4.0.19 Alpha")]
|
Reference in New Issue
Block a user