diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 696a18ab9..00cae20cd 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -17,10 +17,11 @@ use std::{ path::PathBuf, sync::{Arc, Mutex}, time::{Duration, Instant}, + collections::HashMap }; use winapi::{ ctypes::c_void, - shared::{minwindef::*, ntdef::NULL, windef::*}, + shared::{minwindef::*, ntdef::NULL, windef::*, winerror::*}, um::{ errhandlingapi::GetLastError, handleapi::CloseHandle, @@ -1762,9 +1763,15 @@ pub fn send_message_to_hnwd( } pub fn create_process_with_logon(user: &str, pwd: &str, exe: &str, arg: &str) -> ResultType<()> { + let last_error_table = HashMap::from([ + (ERROR_LOGON_FAILURE, "The user name or password is incorrect."), + (ERROR_ACCESS_DENIED, "Access is denied.") + ]); + unsafe { - let wuser = wide_string(user); - let wpc = wide_string(""); + let user_split = user.split("\\").collect::>(); + let wuser = wide_string(user_split.get(1).unwrap_or(&user)); + let wpc = wide_string(user_split.get(0).unwrap_or(&"")); let wpwd = wide_string(pwd); let cmd = if arg.is_empty() { format!("\"{}\"", exe) @@ -1794,7 +1801,14 @@ pub fn create_process_with_logon(user: &str, pwd: &str, exe: &str, arg: &str) -> &mut pi as *mut PROCESS_INFORMATION, ) { - bail!("CreateProcessWithLogonW failed, errno={}", GetLastError()); + let last_error = GetLastError(); + bail!( + "CreateProcessWithLogonW failed : \"{}\", errno={}", + last_error_table + .get(&last_error) + .unwrap_or(&"Unknown error"), + last_error + ); } } return Ok(()); @@ -1804,7 +1818,7 @@ pub fn set_path_permission(dir: &PathBuf, permission: &str) -> ResultType<()> { std::process::Command::new("icacls") .arg(dir.as_os_str()) .arg("/grant") - .arg(format!("Everyone:(OI)(CI){}", permission)) + .arg(format!("*S-1-1-0:(OI)(CI){}", permission)) .arg("/T") .spawn()?; Ok(())