So, when you open a command prompt in Windows you can map network shares to Windows drives by using:
net use Q: \\SERVER\SHARE /user:Alice pa$$word /P
Q:\\SERVER\SHARE/user:Alice pa$$word/P
Executing this in Go would look something like:
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))
}
这篇关于使用golang映射Windows驱动器的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!