windows - 如何在 msysgit/Cygwin 脚本中测试管理员权限?

标签 windows bash command-line cygwin msysgit

如何测试您是否在 msysgit/Cygwin 的脚本中具有管理员权限?在我的机器上,以管理员身份打开 Git Bash 并运行 whoami 仍然输出 James,而不是 root

我想你可能会做类似的事情

if touch /C/file.txt && rm /C/file.txt; then
    echo 'Admin!'
else
    echo 'Not admin!'
fi

但这感觉非常骇人听闻。有没有更好的方法来做到这一点?

编辑:还尝试了 idid -G,但它们对管理终端和常规终端的输出相同。

最佳答案

Batch找到解决方案:

if net session &> /dev/null; then
    echo 'Admin!'
else
    echo 'Not admin!'
fi

关于windows - 如何在 msysgit/Cygwin 脚本中测试管理员权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34497888/

相关文章:

c++ - VS2015 的多处理器编译在运行 cl.exe 时产生 "not enough quota is available to process this command"

Perl 从命令行 : When replace a string in a file it removes also the new lines

c++ - 如何在 Windows 上的 C++ 中管理文件/目录的发现和使用?

windows - Windows中通过Maven构建的Hadoop不断失败

node.js - 在 Windows 上安装 npm 后无法识别 node_modules

java - 如何使用 spark-submit 将参数/属性传递给 Spark 作业

bash - 如何使用 cat 进行编程?

linux - ./executable 和 . 之间的区别可执行的

bash - Shell脚本中的十六进制到十进制

linux - shell解析csv文件,将字段分配给变量并在多列中打印