有没有办法用golang获取Windows用户名?我也想得到一个域名。在我的例子中,域是"WORKGROUP“
cmd ->系统信息:

发布于 2020-05-17 06:30:12
您必须使用os和os/user程序包来处理域和当前用户名
package main
import (
"fmt"
"os"
"os/user"
)
func main() {
fmt.Println(user.Current()) //return current username
fmt.Println(os.Hostname()) //return the hostname(domain)
}发布于 2020-11-25 21:44:31
user.Current()返回当前运行应用程序的用户。它不会返回您需要使用golang的windows包("golang.org/x/sys/windows")的WTS函数并检索当前活动会话的会话详细信息的当前登录用户。
https://stackoverflow.com/questions/61840740
复制相似问题