Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(windows): run wmic and where by absolute path

James Dama89800f67ee8
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rs
index a5768f304..062e1d739 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rs
@@ -348,9 +348,9 @@ pub(crate) fn which(name: &str) -> Option<PathBuf> {
/// Every match for `name` on PATH, in PATH order.
fn which_all(name: &str) -> Vec<PathBuf> {
#[cfg(unix)]
- let finder = "which";
+ let finder = PathBuf::from("which");
#[cfg(windows)]
- let finder = "where";
+ let finder = system32_dir().join("where.exe");
let Ok(out) = std::process::Command::new(finder).arg(name).output() else {
return Vec::new();
};
diff --git a/src-tauri/utils/src/network.rs b/src-tauri/utils/src/network.rs
index df713c25a..fbd1095af 100644
--- a/src-tauri/utils/src/network.rs
+++ b/src-tauri/utils/src/network.rs
@@ -311,7 +311,9 @@ fn get_process_command_line(pid: u32) -> Option<Vec<String>> {
#[cfg(windows)]
use std::os::windows::process::CommandExt;
- let mut cmd = Command::new("wmic");
+ // Absent on newer Windows 11 builds: then the spawn fails and the caller
+ // gets None, i.e. the process is unknown.
+ let mut cmd = Command::new(crate::windows_system_tool(r"wbem\wmic.exe"));
cmd.args(&[
"process",
"where",
@@ -393,8 +395,9 @@ fn get_process_info_by_pid_windows(pid: u32) -> Option<ProcessUsingPort> {
#[cfg(windows)]
use std::os::windows::process::CommandExt;
- // Use wmic to get process info by PID
- let mut cmd = Command::new("wmic");
+ // Use wmic to get process info by PID. Absent on newer Windows 11 builds:
+ // then the spawn fails and the caller gets None, i.e. the process is unknown.
+ let mut cmd = Command::new(crate::windows_system_tool(r"wbem\wmic.exe"));
cmd.args(&[
"process",
"where",
diff --git a/src-tauri/utils/src/system.rs b/src-tauri/utils/src/system.rs
index cd1980931..dccc5416b 100644
--- a/src-tauri/utils/src/system.rs
+++ b/src-tauri/utils/src/system.rs
@@ -673,6 +673,10 @@ mod tests {
system32_path(Some(OsString::from(r"D:\Win\")), "cmd.exe"),
PathBuf::from(r"D:\Win\System32\cmd.exe")
);
+ assert_eq!(
+ system32_path(Some(OsString::from(r"D:\Win")), r"wbem\wmic.exe"),
+ PathBuf::from(r"D:\Win\System32\wbem\wmic.exe")
+ );
}
#[test]