简体   繁体   English

以管理员身份运行Go程序

[英]Running Go Program as Admin

I'm trying to run a Go program with admin rights in Windows. 我正在尝试在Windows中运行带有管理员权限的Go程序。 Like sudo in Linux. 就像Linux中的sudo一样。 To do that I'm launching cmd as Administrator. 为此,我将以管理员身份启动cmd。 I also tried runas administrator command. 我也试过runas管理员命令。

The problem is os.Getuid() function returns -1. 问题是os.Getuid()函数返回-1。 The program checks it and if it is not 0 it tells, you don't have the admin rights. 程序检查它,如果它不是0,它告诉你,你没有管理员权限。

Code snippet from the Go program Gor (listener.go): 来自Go程序Gor(listener.go)的代码片段:

if os.Getuid() != 0 {
    fmt.Println("Please start the listener as root or sudo!")
    fmt.Println("This is required since listener sniff traffic on given port.")
    os.Exit(1)
}

Is there any solution for this issue? 这个问题有什么解决方案吗?

Thanks 谢谢

The flagship version of Go was developed by the principal Go authors for Linux/Darwin, with an architecture that allowed for other operating systems. Go的旗舰版本由Linux / Darwin的主要Go作者开发,其架构允许其他操作系统。 Later, others came along and ported Go to other operating systems like Windows. 后来,其他人出现并将Go移植到Windows等其他操作系统。 Some of the Windows port is flawed and incomplete. 某些Windows端口存在缺陷且不完整。 Also, some Linux/Darwin features, like the security model, don't have a direct analogue in Windows. 此外,某些Linux / Darwin功能(如安全模型)在Windows中没有直接模拟功能。

syscall_windows.go : syscall_windows.go

. . .
// TODO(brainman): fix all needed for os
. . .
func Getuid() (uid int) { return -1 }
. . .

Open a new issue on the Go issue tracker . 在Go 问题跟踪器上打开一个新问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM