mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-12-12 02:09:12 +08:00
fix wallpaper get sid (#9058)
Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
parent
f6ab5cdcb2
commit
07cf1b4db5
@ -2370,34 +2370,6 @@ fn get_license() -> Option<CustomServer> {
|
||||
Some(lic)
|
||||
}
|
||||
|
||||
fn get_sid_of_user(username: &str) -> ResultType<String> {
|
||||
let mut output = Command::new("wmic")
|
||||
.args(&[
|
||||
"useraccount",
|
||||
"where",
|
||||
&format!("name='{}'", username),
|
||||
"get",
|
||||
"sid",
|
||||
"/value",
|
||||
])
|
||||
.creation_flags(CREATE_NO_WINDOW)
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()?
|
||||
.stdout
|
||||
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Failed to open stdout"))?;
|
||||
let mut result = String::new();
|
||||
output.read_to_string(&mut result)?;
|
||||
let sid_start_index = result
|
||||
.find('=')
|
||||
.map(|i| i + 1)
|
||||
.ok_or(anyhow!("bad output format"))?;
|
||||
if sid_start_index > 0 && sid_start_index < result.len() + 1 {
|
||||
Ok(result[sid_start_index..].trim().to_string())
|
||||
} else {
|
||||
bail!("bad output format");
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WallPaperRemover {
|
||||
old_path: String,
|
||||
}
|
||||
@ -2433,12 +2405,7 @@ impl WallPaperRemover {
|
||||
// https://www.makeuseof.com/find-desktop-wallpapers-file-location-windows-11/
|
||||
// https://superuser.com/questions/1218413/write-to-current-users-registry-through-a-different-admin-account
|
||||
let (hkcu, sid) = if is_root() {
|
||||
let username = get_active_username();
|
||||
if username.is_empty() {
|
||||
bail!("failed to get username");
|
||||
}
|
||||
let sid = get_sid_of_user(&username)?;
|
||||
log::info!("username: {username}, sid: {sid}");
|
||||
let sid = get_current_process_session_id().ok_or(anyhow!("failed to get sid"))?;
|
||||
(RegKey::predef(HKEY_USERS), format!("{}\\", sid))
|
||||
} else {
|
||||
(RegKey::predef(HKEY_CURRENT_USER), "".to_string())
|
||||
@ -2612,8 +2579,7 @@ pub mod reg_display_settings {
|
||||
new: (Vec<u8>, isize),
|
||||
}
|
||||
|
||||
pub fn read_reg_connectivity() -> ResultType<HashMap<String, HashMap<String, RegValue>>>
|
||||
{
|
||||
pub fn read_reg_connectivity() -> ResultType<HashMap<String, HashMap<String, RegValue>>> {
|
||||
let hklm = winreg::RegKey::predef(HKEY_LOCAL_MACHINE);
|
||||
let reg_connectivity = hklm.open_subkey_with_flags(
|
||||
format!("{}\\{}", REG_GRAPHICS_DRIVERS_PATH, REG_CONNECTIVITY_PATH),
|
||||
|
Loading…
Reference in New Issue
Block a user