go - What is the best way to map windows drives using golang? -


what best way map network share windows drive using go-lang? share requires username , password. similar question asked python what best way map windows drives using python?

as of there no direct way in go; recommend using net use, of course limits functionality windows, that's need.

so, when open command prompt in windows can map network shares windows drives using:

net use q: \\server\share /user:alice pa$$word /p

q: represents windows drive, \\server\share network address, /user:alice pa$$word credentials, , /p persistence.

executing in go like:

func mapdrive(letter string, address string, user string, pw string) ([]byte, error) {   // return combined output std , 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)) } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -