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 LoadDriver(string svcName, string path) { string regPath = "CurrentControlSet\\Services\\" + svcName; RegistryKey svcKey = Registry.LocalMachine.CreateSubKey("SYSTEM\\" + regPath); svcKey.SetValue("ImagePath", "\\??\\" + path); svcKey.SetValue("Type", 1); SYS.UNICODE_STRING uRegPath = new SYS.UNICODE_STRING(); bool enabled; var status = SYS.RtlAdjustPrivilege(SYS.SeLoadDriverPrivilege, true, SYS.ADJUST_PRIVILEGE_TYPE.AdjustCurrentProcess, out enabled); SYS.RtlInitUnicodeString(ref uRegPath, "\\Registry\\Machine\\SYSTEM\\" + regPath); return(SYS.NtLoadDriver(ref uRegPath)); }