/// <summary> /// Creates a connection to KProcessHacker. /// </summary> /// <param name="deviceName">The device to connect to.</param> public KBugCheck(string deviceName) { _deviceName = deviceName; bool started = false; // delete the service if it exists try { using (var shandle = new Win32.ServiceHandle(deviceName)) { started = shandle.GetStatus().CurrentState == Win32.SERVICE_STATE.Running; if (!started) { shandle.Delete(); } } } catch { } try { Win32.ServiceManagerHandle scm = new Win32.ServiceManagerHandle(Win32.SC_MANAGER_RIGHTS.SC_MANAGER_CREATE_SERVICE); _service = scm.CreateService(deviceName, deviceName, Win32.SERVICE_TYPE.KernelDriver, Application.StartupPath + "\\kbugcheck.sys"); _service.Start(); } catch { } _fileHandle = new Win32.FileHandle("\\\\.\\" + deviceName, Win32.FILE_RIGHTS.FILE_GENERIC_READ | Win32.FILE_RIGHTS.FILE_GENERIC_WRITE); try { if (!started) { _service.Delete(); // the service will automatically get deleted once it stops } } catch { } _baseControlNumber = Misc.BytesToUInt(_fileHandle.Read(4), Misc.Endianness.Little); }
/// <summary> /// Creates a connection to KProcessHacker. /// </summary> /// <param name="deviceName">The device to connect to.</param> public KBugCheck(string deviceName) { _deviceName = deviceName; bool started = false; // delete the service if it exists try { using (var shandle = new Win32.ServiceHandle(deviceName)) { started = shandle.GetStatus().CurrentState == Win32.SERVICE_STATE.Running; if (!started) shandle.Delete(); } } catch { } try { Win32.ServiceManagerHandle scm = new Win32.ServiceManagerHandle(Win32.SC_MANAGER_RIGHTS.SC_MANAGER_CREATE_SERVICE); _service = scm.CreateService(deviceName, deviceName, Win32.SERVICE_TYPE.KernelDriver, Application.StartupPath + "\\kbugcheck.sys"); _service.Start(); } catch { } _fileHandle = new Win32.FileHandle("\\\\.\\" + deviceName, Win32.FILE_RIGHTS.FILE_GENERIC_READ | Win32.FILE_RIGHTS.FILE_GENERIC_WRITE); try { if (!started) _service.Delete(); // the service will automatically get deleted once it stops } catch { } _baseControlNumber = Misc.BytesToUInt(_fileHandle.Read(4), Misc.Endianness.Little); }