drh37116 2013-07-10 12:01
浏览 555
已采纳

以管理员身份运行Go程序

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

  • 写回答

1条回答 默认 最新

  • douzhong6480 2013-07-10 13:13
    关注

    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.

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”