Fix Windows auto-launch registration for restart/login#3239
Fix Windows auto-launch registration for restart/login#3239piaoguodeafei wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the auto-launcher implementation on Windows to utilize the Task Scheduler via schtasks, replacing legacy registry-based entries. Key changes include the addition of task management helpers, unit tests for Windows-specific task arguments, and a modification to the task's execution run level. Review feedback points out that lowering the run level to LUA may cause launch failures if the application manifest requires administrative privileges. Additionally, it is recommended to suppress stderr output during task existence checks to avoid unnecessary log noise.
| id: "Tari universe principal".to_string(), | ||
| logon_type: LogonType::InteractiveToken, | ||
| run_level: RunLevel::Highest, | ||
| run_level: RunLevel::LUA, |
There was a problem hiding this comment.
Changing the run_level to RunLevel::LUA (Least Privileged User Account) might prevent the application from starting if its manifest requires administrator privileges (requireAdministrator). The PR description mentions that the app manifest requests administrator privileges and that running without a compatibility layer fails with error 740. In such cases, Task Scheduler will fail to launch the process unless the task itself is run with highest privileges. If the intention is to have the app auto-launch successfully while requiring admin, RunLevel::Highest is usually necessary to bypass the UAC prompt at logon.
| fn startup_task_exists(&self) -> Result<bool, Box<dyn std::error::Error>> { | ||
| let status = Command::new("schtasks") | ||
| .args(windows_query_task_args()) | ||
| .status()?; | ||
|
|
||
| Ok(status.success()) | ||
| } |
There was a problem hiding this comment.
The schtasks /Query command prints an error message to stderr if the task does not exist. Since this function is called to check for existence, these error messages might clutter the console or logs when the app is run from a terminal. It is better to redirect the output to Stdio::null() to keep the output clean.
| fn startup_task_exists(&self) -> Result<bool, Box<dyn std::error::Error>> { | |
| let status = Command::new("schtasks") | |
| .args(windows_query_task_args()) | |
| .status()?; | |
| Ok(status.success()) | |
| } | |
| fn startup_task_exists(&self) -> Result<bool, Box<dyn std::error::Error>> { | |
| let status = Command::new("schtasks") | |
| .args(windows_query_task_args()) | |
| .stdout(std::process::Stdio::null()) | |
| .stderr(std::process::Stdio::null()) | |
| .status()?; | |
| Ok(status.success()) | |
| } |
Tari Universe Windows Auto-Launch PR Draft
Title
Fix Windows auto-launch registration for restart/login
Summary
auto-launchregistry entry.schtasksarguments.data_location.rsby definingDRIVE_REMOTElocally; the currentwindows-sysdependency exposesGetDriveTypeWfromStorage::FileSystem, butDRIVE_REMOTEis not exported from that module.Verification
git diff --checkpassed locally.cargo fmt -- --checkpassed locally.process-wrappersidecar withcargo build --manifest-path process-wrapper/Cargo.toml.cargo test auto_launcher::tests::passed locally on Windows: 3 passed, 0 failed, 189 filtered out.__COMPAT_LAYER=RunAsInvokerfails with Windows UACos error 740because the app manifest requests administrator privileges. The compatibility layer was used only to run the unit tests without elevation.Local Commit
389cb72 fix: use task scheduler for Windows auto-launchIssue
Closes #1588