mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
@@ -24,7 +24,7 @@ use winapi::{
|
||||
minwinbase::STILL_ACTIVE,
|
||||
processthreadsapi::{
|
||||
GetCurrentProcess, GetCurrentProcessId, GetExitCodeProcess, OpenProcess,
|
||||
OpenProcessToken,
|
||||
OpenProcessToken, PROCESS_INFORMATION, STARTUPINFOW,
|
||||
},
|
||||
securitybaseapi::GetTokenInformation,
|
||||
shellapi::ShellExecuteW,
|
||||
@@ -1714,3 +1714,42 @@ pub fn send_message_to_hnwd(
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn create_process_with_logon(user: &str, pwd: &str, exe: &str, arg: &str) -> ResultType<()> {
|
||||
unsafe {
|
||||
let wuser = wide_string(user);
|
||||
let wpc = wide_string("");
|
||||
let wpwd = wide_string(pwd);
|
||||
let cmd = if arg.is_empty() {
|
||||
format!("\"{}\"", exe)
|
||||
} else {
|
||||
format!("\"{}\" {}", exe, arg)
|
||||
};
|
||||
let mut wcmd = wide_string(&cmd);
|
||||
let mut si: STARTUPINFOW = mem::zeroed();
|
||||
si.wShowWindow = SW_HIDE as _;
|
||||
si.lpDesktop = NULL as _;
|
||||
si.cb = std::mem::size_of::<STARTUPINFOW>() as _;
|
||||
si.dwFlags = STARTF_USESHOWWINDOW;
|
||||
let mut pi: PROCESS_INFORMATION = mem::zeroed();
|
||||
let wexe = wide_string(exe);
|
||||
if FALSE
|
||||
== CreateProcessWithLogonW(
|
||||
wuser.as_ptr(),
|
||||
wpc.as_ptr(),
|
||||
wpwd.as_ptr(),
|
||||
LOGON_WITH_PROFILE,
|
||||
wexe.as_ptr(),
|
||||
wcmd.as_mut_ptr(),
|
||||
CREATE_UNICODE_ENVIRONMENT,
|
||||
NULL,
|
||||
NULL as _,
|
||||
&mut si as *mut STARTUPINFOW,
|
||||
&mut pi as *mut PROCESS_INFORMATION,
|
||||
)
|
||||
{
|
||||
bail!("CreateProcessWithLogonW failed, errno={}", GetLastError());
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user