private static SYS.NTSTATUS UnloadDriver(string svcName) { bool enabled; string regPath = "CurrentControlSet\\Services\\" + svcName; SYS.UNICODE_STRING uRegPath = new SYS.UNICODE_STRING(); SYS.NTSTATUS status = SYS.RtlAdjustPrivilege(SYS.SeLoadDriverPrivilege, true, SYS.ADJUST_PRIVILEGE_TYPE.AdjustCurrentProcess, out enabled); SYS.RtlInitUnicodeString(ref uRegPath, "\\Registry\\Machine\\SYSTEM\\" + regPath); status = SYS.NtUnloadDriver(ref uRegPath); Registry.LocalMachine.DeleteSubKeyTree("SYSTEM\\" + regPath, false); return(status); }
private static SYS.NTSTATUS Reload(string path) { Define.Unload(); if (String.IsNullOrWhiteSpace(path)) { return(SYS.NTSTATUS.ObjectPathNotFound); } SYS.NTSTATUS status = Define.LoadDriver(Define.nameDriver, path); if (status >= 0) { Define.Handle = SYS.CreateFile(Define.linkDriver, FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); if (Define.Handle == null || Define.Handle.IsInvalid) { return((SYS.NTSTATUS)Marshal.GetLastWin32Error()); } } return(SYS.NTSTATUS.Success); }