feat: basic crticality
This commit is contained in:
parent
f69929bc73
commit
6b00f0586e
4 changed files with 38 additions and 2 deletions
|
|
@ -90,3 +90,25 @@ pub fn run_as_user(app: &str, cmd: &str) -> anyhow::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mark_process_critical() -> anyhow::Result<()> {
|
||||
use ntapi::ntpsapi::{NtSetInformationProcess, ProcessBreakOnTermination};
|
||||
use ntapi::winapi::{ctypes::c_void, um::winnt::HANDLE};
|
||||
|
||||
unsafe {
|
||||
// NtCurrentProcess pseudo-handle (-1)
|
||||
let handle: HANDLE = (-1isize) as usize as *mut c_void;
|
||||
let mut critical: u32 = 1;
|
||||
let status = NtSetInformationProcess(
|
||||
handle,
|
||||
ProcessBreakOnTermination,
|
||||
&mut critical as *mut _ as *mut _,
|
||||
core::mem::size_of::<u32>() as u32,
|
||||
);
|
||||
if status == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
anyhow::bail!(format!("NtSetInformationProcess failed: 0x{status:08X}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue