Skip to content

Commit

Permalink
fix wallpaper get sid (rustdesk#9058)
Browse files Browse the repository at this point in the history
Signed-off-by: 21pages <[email protected]>
  • Loading branch information
21pages authored Aug 14, 2024
1 parent f6ab5cd commit 07cf1b4
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 07cf1b4

Please sign in to comment.