elevation: keyboard permission required and remove foreground filter

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-09-30 19:47:59 +08:00
parent d8e51c6b14
commit 17a56bbf48
41 changed files with 69 additions and 45 deletions

View File

@@ -1587,29 +1587,6 @@ pub fn is_elevated(process_id: Option<DWORD>) -> ResultType<bool> {
}
}
#[inline]
fn filter_foreground_window(process_id: DWORD) -> ResultType<bool> {
if let Ok(output) = std::process::Command::new("tasklist")
.args(vec![
"/SVC",
"/NH",
"/FI",
&format!("PID eq {}", process_id),
])
.creation_flags(CREATE_NO_WINDOW)
.output()
{
let s = String::from_utf8_lossy(&output.stdout)
.to_string()
.to_lowercase();
Ok(["Taskmgr", "mmc", "regedit"]
.iter()
.any(|name| s.contains(&name.to_string().to_lowercase())))
} else {
bail!("run tasklist failed");
}
}
pub fn is_foreground_window_elevated() -> ResultType<bool> {
unsafe {
let mut process_id: DWORD = 0;
@@ -1617,12 +1594,7 @@ pub fn is_foreground_window_elevated() -> ResultType<bool> {
if process_id == 0 {
bail!("Failed to get processId, errno {}", GetLastError())
}
let elevated = is_elevated(Some(process_id))?;
if elevated {
filter_foreground_window(process_id)
} else {
Ok(false)
}
is_elevated(Some(process_id))
}
}