简体   繁体   English

如何获得对联网位置的访问权限?

[英]How can I obtain access to a networked location?

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.该程序使用任务计划程序与 PC 一起启动。 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 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 administrator after the program enters its loop.如果任何其他应用程序在程序进入其循环后as administrator启动,则该程序将成功。

On Task Scheduler you can delay the execution of the task.在任务计划程序上,您可以延迟任务的执行。

It's okay if you execute it after login, but when Active Directory or anyway a Domain system is between you and the login, the connection to the shared storage may take a while, and the program may try to execute before this happens.如果您在登录后执行它没关系,但是当您和登录之间存在 Active Directory 或任何域系统时,与共享存储的连接可能需要一段时间,并且程序可能会在此发生之前尝试执行。 Try to put on a 10-20 seconds delay on it and see if this solve your problem.尝试延迟 10-20 秒,看看这是否能解决您的问题。

If it doesn't work, again supposing that you have a domain in the middle, you may need to explicit give user and passwd to access the network where the directory you're looking for.如果它不起作用,再次假设您在中间有一个域,您可能需要显式地给用户和密码以访问您正在寻找的目录所在的网络。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM