const fn from_win32(code: u32) -> i32 {
(0x8007_0000 | code) as i32
}
pub(crate) const ERROR_FILE_NOT_FOUND: i32 = from_win32(2);
pub(crate) const ERROR_PATH_NOT_FOUND: i32 = from_win32(3);
pub(crate) const ERROR_ACCESS_DENIED: i32 = from_win32(5);
#[cfg(test)]
pub(crate) const ERROR_NOT_ENOUGH_MEMORY: i32 = from_win32(8);
pub(crate) const ERROR_SHARING_VIOLATION: i32 = from_win32(32);
pub(crate) const ERROR_BAD_EXE_FORMAT: i32 = from_win32(193);
pub(crate) const ERROR_EXE_MACHINE_TYPE_MISMATCH: i32 = from_win32(216);
pub(crate) const ERROR_CANCELLED: i32 = from_win32(1223);
pub(crate) const ERROR_NO_ASSOCIATION: i32 = from_win32(1155);
#[cfg(test)]
pub(crate) const ERROR_DDE_FAIL: i32 = from_win32(1156);
pub(crate) const ERROR_DLL_NOT_FOUND: i32 = from_win32(1157);
pub(crate) const SE_ERR_DDETIMEOUT: isize = 28;
pub(crate) const SE_ERR_DDEFAIL: isize = 29;
pub(crate) const SE_ERR_DDEBUSY: isize = 30;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum RunasFailure {
Declined,
BeforeLaunch,
MayHaveLaunched,
}
pub(crate) fn classify(code: i32, inst_app: isize) -> RunasFailure {
if code == ERROR_CANCELLED {
return RunasFailure::Declined;
}
let dde = matches!(inst_app, SE_ERR_DDETIMEOUT | SE_ERR_DDEFAIL | SE_ERR_DDEBUSY);
let before_launch = matches!(
code,
ERROR_FILE_NOT_FOUND
| ERROR_PATH_NOT_FOUND
| ERROR_ACCESS_DENIED
| ERROR_SHARING_VIOLATION
| ERROR_NO_ASSOCIATION
| ERROR_DLL_NOT_FOUND
| ERROR_BAD_EXE_FORMAT
| ERROR_EXE_MACHINE_TYPE_MISMATCH
);
if before_launch && !dde {
RunasFailure::BeforeLaunch
} else {
RunasFailure::MayHaveLaunched
}
}
#[cfg(test)]
#[path = "runas_failure_tests.rs"]
mod runas_failure_tests;