Python:如何以管理员权限启动进程?
我正在使用管理员权限从 Windows 7 命令行启动以下脚本:
import win32com.client
import time
import SendKeys
import os
from ctypes import *
shell = win32com.client.Dispatch("WScript.Shell")
os.startfile("C:\...exe")
我还在“属性”>“属性”下将“以管理员身份运行此程序”功能分配给 python.exe。兼容性>特权级别。这并没有改变任何事情。
以这种方式打开时,该程序的行为仍然与我通过双击屏幕打开它时的行为不同。我在这里遗漏了一些重要的部分吗?这样调用的进程会不会像以管理员权限启动一样运行?
提前感谢您的帮助!
干杯 -
帕特
I am starting the following script from a Windows 7 command line with administrator permissions:
import win32com.client
import time
import SendKeys
import os
from ctypes import *
shell = win32com.client.Dispatch("WScript.Shell")
os.startfile("C:\...exe")
I have also assigned the feature 'Run this programme as an administrator' to python.exe under Properties > Compatibility > Privilege Level. This did not change anything.
The programme still behaves differently when opened this way to how it behaves when I just open it via a double click on screen. Am I missing some important bit here? Will the process invoked in this way not be run as if started with administrator privileges?
Thanks for your help in advance!
Cheers -
Pat
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法访问 Vista 或 Windows 7,但您应该能够使用
runas
命令。I don't have access to Vista or Windows 7, but you should be able to use the
runas
command.好吧...我知道问题出在哪里了。它实际上与权限无关,这与我最初的怀疑相反。对此感到抱歉!
应用程序无法正常工作的原因是Python脚本位于另一个目录中并被调用。因此,应用程序的某些依赖项未正确引用,并且无法找到正确运行所需的某些文件。将 python 脚本移动到与调用的应用程序相同的目录中是解决此问题的一种方法。
对于对问题的初步解释产生误导,再次表示歉意。
OK ... I figured out what the problem was. It actually had nothing to do with permissions, contrary to my initial suspicion. Sorry about that!
The reason why the application did not work correctly was because the Python script was located and invoked in another directory. For that reason, some of the application's dependencies were not referenced correctly and it couldn't find some of the files it needs to run properly. Moving the python script into the same directory as the invoked application was one way to fix that.
Sorry again for the misleading initial interpretation of what seemed to be the matter.