use std::os::windows::fs;
// https://doc.rust-lang.org/std/os/windows/fs/fn.symlink_file.html
use std::io::*;
use std::io::{self, Read, Stdin};
fn input_from() -> io::Result<()> {
let mut buffer = String::new();
let mut stdin = io::stdin(); // We get `Stdin` here.
stdin.read_to_string(&mut buffer)?;
Ok(())
}
fn main() -> std::io::Result<()> {
let mut shortcut_dir = String::from("D:\\winr\\");
println!("Your script path:");
let mut buffer1 = String::new();
let mut stdin = io::stdin();
stdin
.read_line(&mut buffer1)
.expect("error: unable to read user input");
buffer1.pop();
println!("Your shortcut name:");
let mut buffer2 = String::new();
let mut stdin: Stdin = io::stdin();
stdin
.read_line(&mut buffer2)
.expect("error: unable to read user input");
println!("buffer1 is:{:?}", buffer1);
buffer2.pop();
let mut buffer2 = &buffer2[..];
println!("buffer2 is:{:?}", buffer2);
shortcut_dir.push_str(&buffer2);
let mut buffer3 = shortcut_dir;
println!("buffer3 is:{:?}", buffer3);
fs::symlink_file(buffer1, buffer3)?;
Ok(())
}
It complains:
Error: Os { code: 1314, kind: Other, message: "A required privilege is not held by the client" }
error: process didn't exit successfully: `target\debug\ssdkqn.exe` (exit code: 1)
I use Windows. When I run this script in Administrator mode, the problem goes away. Why does it need the Administrator privilege to create a symlink?