我正在尝试编写一个python脚本来请求根权限。我尝试过使用elevate for python,但在运行它时出现了“没有这样的文件或目录”错误。在
import os
from elevate import elevate
def is_root():
return os.getuid() == 0
print("before ", is_root())
elevate()
print("after ", is_root())
为什么会这样?有没有其他可以利用系统图形用户界面的替代方案?
编辑:
我将Linux与Python3.6一起使用,但我希望它能在Windows上工作。在
这里有一个完整的解决方案,它可以在Windows和Linux下将UAC或sudo提升为root用户,不管代码是用Nuitka解释、冻结还是编译的。在
代码基本上检查它是否已经被提升,如果是,则运行main()函数;如果没有,则生成一个提升的子进程,该子进程将运行main()函数。在
希望有帮助
相关问题 更多 >
编程相关推荐