Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ os_info = { version = "3", default-features = false }
dirs = "^6"

[target.'cfg(windows)'.dependencies]
windows-registry = "^0.6"
windows-result = "^0.4"
windows-registry = ">=0.5, <=0.6"

[target.'cfg(target_os = "macos")'.dependencies]
smappservice-rs = "0.1"
17 changes: 8 additions & 9 deletions src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use crate::{AutoLaunch, Result, WindowsEnableMode};
use std::io;
use windows_registry::{Key, CURRENT_USER, LOCAL_MACHINE};
use windows_result::HRESULT;

const AL_REGKEY: &str = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
const TASK_MANAGER_OVERRIDE_REGKEY: &str =
r"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run";
const TASK_MANAGER_OVERRIDE_ENABLED_VALUE: [u8; 12] = [
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
const E_ACCESSDENIED: HRESULT = HRESULT::from_win32(0x80070005_u32);
const E_FILENOTFOUND: HRESULT = HRESULT::from_win32(0x80070002_u32);
const E_ACCESSDENIED: i32 = 0x80070005_u32 as _;
const ERROR_FILE_NOT_FOUND: i32 = 0x80070002_u32 as _;

/// Windows implement
impl AutoLaunch {
Expand Down Expand Up @@ -48,7 +47,7 @@ impl AutoLaunch {
WindowsEnableMode::Dynamic => self
.enable_as_admin()
.or_else(|e| {
if e.code() == E_ACCESSDENIED {
if e.code().0 == E_ACCESSDENIED {
self.enable_as_current_user()
} else {
Err(e)
Expand Down Expand Up @@ -87,7 +86,7 @@ impl AutoLaunch {
windows_registry::Type::Bytes,
&TASK_MANAGER_OVERRIDE_ENABLED_VALUE,
)?,
Err(error) if error.code() == E_FILENOTFOUND => {
Err(error) if error.code().0 == ERROR_FILE_NOT_FOUND => {
return Ok(());
}
Err(error) => {
Expand All @@ -106,7 +105,7 @@ impl AutoLaunch {
pub fn disable(&self) -> Result<()> {
// try to delete both admin and current user registry values
if let Err(error) = self.disable_as_admin() {
if error.code() == E_ACCESSDENIED {
if error.code().0 == E_ACCESSDENIED {
match self.enable_mode {
// Fail if our enable mode is system but we don't have the access
WindowsEnableMode::System => return Err(std::io::Error::from(error).into()),
Expand Down Expand Up @@ -138,7 +137,7 @@ impl AutoLaunch {
.and_then(|key| key.remove_value(&self.app_name))
{
Ok(_) => Ok(()),
Err(error) if error.code() == E_FILENOTFOUND => Ok(()),
Err(error) if error.code().0 == ERROR_FILE_NOT_FOUND => Ok(()),
Err(error) => Err(error),
}
}
Expand All @@ -161,7 +160,7 @@ impl AutoLaunch {
.and_then(|key| key.get_string(&self.app_name))
{
Ok(_) => true,
Err(error) if error.code() == E_FILENOTFOUND => false,
Err(error) if error.code().0 == ERROR_FILE_NOT_FOUND => false,
Err(error) => {
return Err(error.into());
}
Expand All @@ -175,7 +174,7 @@ impl AutoLaunch {
.and_then(|key| key.get_value(&self.app_name))
{
Ok(value) => last_eight_bytes_all_zeros(&value).unwrap_or(true),
Err(error) if error.code() == E_FILENOTFOUND => true,
Err(error) if error.code().0 == ERROR_FILE_NOT_FOUND => true,
Err(error) => {
return Err(error.into());
}
Expand Down
Loading