I'm trying to run a Go program with admin rights in Windows. Like sudo in Linux. To do that I'm launching cmd as Administrator. I also tried runas administrator command.
The problem is os.Getuid()
function returns -1. The program checks it and if it is not 0 it tells, you don't have the admin rights.
Code snippet from the Go program 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. Later, others came along and ported Go to other operating systems like Windows. Some of the Windows port is flawed and incomplete. Also, some Linux/Darwin features, like the security model, don't have a direct analogue in Windows.
. . .
// TODO(brainman): fix all needed for os
. . .
func Getuid() (uid int) { return -1 }
. . .
Open a new issue on the Go issue tracker.