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) |     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 { | pub struct WallPaperRemover { | ||||||
|     old_path: String, |     old_path: String, | ||||||
| } | } | ||||||
| @ -2433,12 +2405,7 @@ impl WallPaperRemover { | |||||||
|         // https://www.makeuseof.com/find-desktop-wallpapers-file-location-windows-11/
 |         // 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
 |         // https://superuser.com/questions/1218413/write-to-current-users-registry-through-a-different-admin-account
 | ||||||
|         let (hkcu, sid) = if is_root() { |         let (hkcu, sid) = if is_root() { | ||||||
|             let username = get_active_username(); |             let sid = get_current_process_session_id().ok_or(anyhow!("failed to get sid"))?; | ||||||
|             if username.is_empty() { |  | ||||||
|                 bail!("failed to get username"); |  | ||||||
|             } |  | ||||||
|             let sid = get_sid_of_user(&username)?; |  | ||||||
|             log::info!("username: {username}, sid: {sid}"); |  | ||||||
|             (RegKey::predef(HKEY_USERS), format!("{}\\", sid)) |             (RegKey::predef(HKEY_USERS), format!("{}\\", sid)) | ||||||
|         } else { |         } else { | ||||||
|             (RegKey::predef(HKEY_CURRENT_USER), "".to_string()) |             (RegKey::predef(HKEY_CURRENT_USER), "".to_string()) | ||||||
| @ -2612,8 +2579,7 @@ pub mod reg_display_settings { | |||||||
|         new: (Vec<u8>, isize), |         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 hklm = winreg::RegKey::predef(HKEY_LOCAL_MACHINE); | ||||||
|         let reg_connectivity = hklm.open_subkey_with_flags( |         let reg_connectivity = hklm.open_subkey_with_flags( | ||||||
|             format!("{}\\{}", REG_GRAPHICS_DRIVERS_PATH, REG_CONNECTIVITY_PATH), |             format!("{}\\{}", REG_GRAPHICS_DRIVERS_PATH, REG_CONNECTIVITY_PATH), | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user