net use
因此,当您在Windows中打开命令提示符时,可以使用以下命令将网络共享映射到Windows驱动器:
net use Q: \\SERVER\SHARE /user:Alice pa$$word /P
Q:\\SERVER\SHARE/user:Alice
pa$$word/P
在Go中执行此操作类似于:
func mapDrive(letter string, address string, user string, pw string) ([]byte, error) {
// return combined output for std and err
return exec.Command("net use", letter, address, fmt.Sprintf("/user:%s", user), pw, "/P").CombinedOutput()
}
func main() {
out, err := mapDrive("Q:", `\\SERVER\SHARE`, "Alice", "pa$$word")
if err != nil {
log.Fatal(err)
}
// print whatever comes out
log.Println(string(out))
}