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 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题