public static void Open() { // no implementation for unix systems if (OperatingSystem.IsUnix) { return; } if (driver != null) { return; } // clear the current report report.Length = 0; driver = new KernelDriver("WinRing0_1_2_0"); driver.Open(); if (!driver.IsOpen) { // driver is not loaded, try to install and open fileName = GetTempFileName(); if (fileName != null && ExtractDriver(fileName)) { string installError; if (driver.Install(fileName, out installError)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine("Status: Opening driver failed after install"); } } else { string errorFirstInstall = installError; // install failed, try to delete and reinstall driver.Delete(); // wait a short moment to give the OS a chance to remove the driver Thread.Sleep(2000); string errorSecondInstall; if (driver.Install(fileName, out errorSecondInstall)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine( "Status: Opening driver failed after reinstall"); } } else { report.AppendLine("Status: Installing driver \"" + fileName + "\" failed" + (File.Exists(fileName) ? " and file exists" : "")); report.AppendLine("First Exception: " + errorFirstInstall); report.AppendLine("Second Exception: " + errorSecondInstall); } } } else { report.AppendLine("Status: Extracting driver failed"); } try { // try to delte the driver file if (File.Exists(fileName)) { File.Delete(fileName); } fileName = null; } catch (IOException) { } catch (UnauthorizedAccessException) { } } if (!driver.IsOpen) { driver = null; } string isaMutexName = "Global\\Access_ISABUS.HTP.Method"; try { isaBusMutex = new Mutex(false, isaMutexName); } catch (UnauthorizedAccessException) { try { isaBusMutex = Mutex.OpenExisting(isaMutexName, MutexRights.Synchronize); } catch { } } string pciMutexName = "Global\\Access_PCI"; try { pciBusMutex = new Mutex(false, pciMutexName); } catch (UnauthorizedAccessException) { try { pciBusMutex = Mutex.OpenExisting(pciMutexName, MutexRights.Synchronize); } catch { } } }
private static void InstallKernelDriverCore(string directoryPath) { fileName = GetDriverFileName(directoryPath); if (fileName != null && ExtractDriver(fileName)) { string installError; if (driver.Install(fileName, out installError)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine("Status: Opening driver failed after install"); } } else { string errorFirstInstall = installError; // install failed, try to delete and reinstall driver.Delete(); // wait a short moment to give the OS a chance to remove the driver Thread.Sleep(2000); string errorSecondInstall; if (driver.Install(fileName, out errorSecondInstall)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine( "Status: Opening driver failed after reinstall"); } } else { report.AppendLine("Status: Installing driver \"" + fileName + "\" failed" + (File.Exists(fileName) ? " and file exists" : "")); report.AppendLine("First Exception: " + errorFirstInstall); report.AppendLine("Second Exception: " + errorSecondInstall); } } } else { try { // try to delete the driver file if (File.Exists(fileName)) { File.Delete(fileName); } fileName = null; } catch (IOException) { } catch (UnauthorizedAccessException) { } report.AppendLine("Status: Extracting driver failed"); } }
public static void Open() { // no implementation for unix systems int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) { return; } if (driver != null) { return; } // clear the current report report.Length = 0; driver = new KernelDriver("WinRing0_1_2_0"); driver.Open(); if (!driver.IsOpen) { // driver is not loaded, try to reinstall and open driver.Delete(); fileName = GetTempFileName(); if (fileName != null && ExtractDriver(fileName)) { if (driver.Install(fileName)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine("Status: Opening driver failed"); } } else { 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 failed"); } try { // try to delte the driver file if (File.Exists(fileName)) { File.Delete(fileName); } fileName = null; } catch (IOException) { } catch (UnauthorizedAccessException) { } } if (!driver.IsOpen) { driver = null; } string mutexName = "Global\\Access_ISABUS.HTP.Method"; try { isaBusMutex = new Mutex(false, mutexName); } catch (UnauthorizedAccessException) { try { isaBusMutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize); } catch { } } }
public static void Open() { // no implementation for unix systems if (Software.OperatingSystem.IsLinux) { return; } if (driver != null) { return; } // clear the current report report.Length = 0; driver = new KernelDriver("WinRing0_1_2_0"); driver.Open(); if (!driver.IsOpen) { // driver is not loaded, try to install and open fileName = GetTempFileName(); if (fileName != null && ExtractDriver(fileName)) { string installError; if (driver.Install(fileName, out installError)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine("Status: Opening driver failed after install"); } } else { string errorFirstInstall = installError; // install failed, try to delete and reinstall driver.Delete(); // wait a short moment to give the OS a chance to remove the driver Thread.Sleep(2000); string errorSecondInstall; if (driver.Install(fileName, out errorSecondInstall)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine( "Status: Opening driver failed after reinstall"); } } else { report.AppendLine("Status: Installing driver \"" + fileName + "\" failed" + (File.Exists(fileName) ? " and file exists" : "")); report.AppendLine("First Exception: " + errorFirstInstall); report.AppendLine("Second Exception: " + errorSecondInstall); } } } else { report.AppendLine("Status: Extracting driver failed"); } try { // try to delte the driver file if (File.Exists(fileName)) { File.Delete(fileName); } fileName = null; } catch (IOException) { } catch (UnauthorizedAccessException) { } } if (!driver.IsOpen) { driver = null; } string mutexName = "Global\\Access_ISABUS.HTP.Method"; try { #if NETSTANDARD2_0 isaBusMutex = new Mutex(false, mutexName); #else //mutex permissions set to everyone to allow other software to access the hardware //otherwise other monitoring software cant access var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow); var securitySettings = new MutexSecurity(); securitySettings.AddAccessRule(allowEveryoneRule); isaBusMutex = new Mutex(false, mutexName, out _, securitySettings); #endif } catch (UnauthorizedAccessException) { try { #if NETSTANDARD2_0 isaBusMutex = Mutex.OpenExisting(mutexName); #else isaBusMutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize); #endif } catch { } } }
public static void Open() { // no implementation for unix systems int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) { return; } if (driver != null) { return; } // clear the current report report.Length = 0; driver = new KernelDriver("WinRing0_1_2_0"); driver.Open(); if (!driver.IsOpen) { // driver is not loaded, try to reinstall and open driver.Delete(); string fileName = Path.GetTempFileName(); if (ExtractDriver(fileName)) { if (driver.Install(fileName)) { File.Delete(fileName); driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine("Status: Opening driver failed"); } } else { 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"); } } if (!driver.IsOpen) { driver = null; } isaBusMutex = new Mutex(false, "Global\\Access_ISABUS.HTP.Method"); }