[英]Running a elevated cmd prompt command python
I've searched google etc but am struggling to find a suitable answer...我已经搜索过谷歌等,但正在努力寻找合适的答案......
Whats the easiest way of opening an elevated cmd prompt in python and having python run a command in it?在 python 中打开提升的 cmd 提示符并让 python 在其中运行命令的最简单方法是什么? I don't mind specifying the username and password in the code as its only for testing我不介意在代码中指定用户名和密码作为其仅用于测试
So far I've come up with this:到目前为止,我想出了这个:
subprocess.run(["Enable_IPRouting.bat"])
The 'Enable_IPRouting.bat' simply contains the following at the min: 'Enable_IPRouting.bat' 仅包含以下内容:
runas /profile /user:DESKTOP-GRLIH2J\\Administrator cmd
Now when I run this - it appears to work I get a prompt requesting the admin password and a cmd prompt appears.现在,当我运行它时 - 它似乎可以工作,我收到一个要求管理员密码的提示,并出现一个 cmd 提示。 However when I try to execute a cmd that requires admin privileges I get the usual error: The requested operation requires elevation
但是,当我尝试执行需要管理员权限的 cmd 时,我收到通常的错误: The requested operation requires elevation
What am I missing?我错过了什么?
Thanks谢谢
Have you tried eg你有没有试过例如
os.system('runas /profile /user:DESKTOP-GRLIH2J\Administrator enable_iprouting.cmd')
(if enable_iprouting.cmd
contains the stuff to run elevated)? (如果enable_iprouting.cmd
包含要运行提升的东西)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.