windows Python 使用提升的 UAC 权限运行 Popen() 子进程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6888551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:39:05  来源:igfitidea点击:

Python run Popen( ) subprocess with elevated UAC privleges

pythonwindowssubprocessuac

提问by machine yearning

Possible Duplicate:
Request UAC elevation from within a Python script?

可能的重复:
从 Python 脚本中请求 UAC 提升?

I'd like to execute a series of Java processes from a Python script, but I must run the Java with elevated UAC privleges (as Administrator) in order to get the results I'm expecting. My call right now is basically:

我想从 Python 脚本执行一系列 Java 进程,但我必须以提升的 UAC 权限(作为管理员)运行 Java 才能获得我期望的结果。我现在的电话基本上是:

from subprocess import Popen
callme = 'java weka.doStuff' # Want this to run as Administrator
Popen(callme)

How do I force this process to run as administrator or with some sufficiently high of elevated UAC privileges?

如何强制此进程以管理员身份运行或使用足够高的提升 UAC 权限运行?

采纳答案by plaes

I'm afraid that you cannot use Popen for that.

恐怕您不能为此使用 Popen。

One option would be using win32api.ShellExecuteand setting runasargument to Administrator.

一种选择是使用win32api.ShellExecute并将runas参数设置为管理员。

Another option would be using JPythonitself...

另一种选择是使用JPython本身......