My program, when started up with the system, is unable to access a networked location:
fn main() {
ensure_network("\\\\SERVER\\".to_string());
}
fn ensure_network(network_dir: String) {
let timer = std::time::Instant::now();
let mut prev_counter = 0;
loop {
if std::fs::read_dir(&network_dir).is_ok() {
break;
}
if timer.elapsed().as_secs() > prev_counter + 60 {
println!("Still Failing.");
prev_counter = timer.elapsed().as_secs();
}
std::hint::spin_loop();
}
println!("Network access obtained (Time elapsed: {})",
timer.elapsed().as_secs_f32());
}
Edit (Restating problem after much research into the issue):
This program starts up with the PC using Task Scheduler. It is set to "Run only when user is logged on" and to "Run with highest privileges." However, most of the time the program fails to find the connection and gives the error, "The user name or password is incorrect. (os error 1326)."
- The program succeeds when run manually with administrator privilege.
- On occasion the program will succeed on startup, but this is rare.
- The program will succeed if any other application is started
as administratorafter the program enters its loop.