BigPizzaV3/CodexPlusPlus · error
无法定位 Windows 启动目录
Error message
无法定位 Windows 启动目录
What it means
On Windows, create_startup_shortcut needs the user's Startup folder (via startup_shortcut_path(), typically SHGetKnownFolderPath FOLDERID_Startup). When that path cannot be determined, installing the watcher shortcut fails with this Chinese-language error meaning 'cannot locate the Windows startup directory'.
Solutions
- Ensure the process runs as a normal interactive user whose profile (and Startup folder) exists; avoid running the installer as a service or SYSTEM
- Manually create the shortcut in the Startup folder ('shell:startup') pointing at the launcher, then skip programmatic install
- Check the Windows user profile integrity; for redirected profiles verify the known-folder registration in the registry
Example fix
// before
watcher::install_watcher(&launcher, 9222)?;
// after
match watcher::install_watcher(&launcher, 9222) {
Ok(()) => {},
Err(e) if e.to_string().contains("启动目录") => {
eprintln!("autostart unavailable; create a shortcut in shell:startup manually");
}
Err(e) => return Err(e),
} Defensive patterns
Strategy: fallback
Validate before calling
// precheck: Startup folder must resolve
if dirs::document_dir().is_none() || std::env::var("USERPROFILE").is_err() {
eprintln!("no user profile; autostart shortcut unavailable");
} Try / catch
match watcher::install_watcher(&launcher, port) {
Err(e) if e.to_string().contains("启动目录") => {
eprintln!("create the shortcut manually in shell:startup");
}
other => other?,
} Prevention
- Run install under an interactive user account, not as a service/SYSTEM
- Avoid installer contexts without a loaded user profile
- Offer manual 'shell:startup' instructions as a documented fallback
When it happens
Trigger: Calling install_watcher on Windows when startup_shortcut_path() returns None — the known-folder API fails, e.g. a corrupted/redirected user profile, service account without a user profile, or restricted environment.
Common situations: Running under a service or scheduled context with no interactive user profile; heavily customized/roaming profile where the Startup folder is unavailable; restricted corporate images.
Related errors
- 拒绝删除文件系统根目录:
- File is a reparse point
- Parent directory is a reparse point
- Recovery verification failed
- Reparse observation file
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/d250c20e92a72e3a.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/watcher.rs:859
if !remaining.is_empty() {
let _ = crate::diagnostic_log::append_diagnostic_log(
"watcher.stop_wait_timeout",
serde_json::json!({
"remaining_process_ids": remaining,
"timeout_ms": timeout_ms
}),
);
}
break;
}
std::thread::sleep(Duration::from_millis(interval_ms));
}
}
#[cfg(windows)]
fn create_startup_shortcut(launcher_path: &Path, arguments: &str) -> anyhow::Result<()> {
let Some(shortcut_path) = startup_shortcut_path() else {
anyhow::bail!("无法定位 Windows 启动目录")
};
crate::windows_integration::create_shortcut(&crate::windows_integration::ShortcutSpec {
path: shortcut_path,
target: launcher_path.to_path_buf(),
arguments: arguments.to_string(),
working_directory: launcher_path.parent().map(Path::to_path_buf),
description: "Codex++ watcher".to_string(),
icon: None,
show_minimized: true,
})
}
#[cfg(windows)]
fn spawn_launcher(launcher_path: &Path, debug_port: u16) {
let command = build_spawn_launcher_command(&launcher_path.to_string_lossy(), debug_port);
if let Some((exe, args)) = command.split_first() {
let mut command = Command::new(exe);
commandView on GitHub (pinned to b1ed92e5e4)