4

我从具有管理员权限的 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 分配了“以管理员身份运行此程序”功能。这并没有改变什么。

当以这种方式打开程序时,程序的行为仍然与我通过双击屏幕打开它时的行为方式不同。我在这里遗漏了一些重要的信息吗?以这种方式调用的进程会不会像以管理员权限启动一样运行?

提前感谢您的帮助!

干杯 -

4

2 回答 2

2

我无法访问 Vista 或 Windows 7,但您应该可以使用该runas命令。

import subprocess
subprocess.call(['runas', '/user:Administrator', 'C:/my_program.exe'])
于 2011-01-10T11:43:38.823 回答
0

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.

于 2011-01-10T12:05:23.260 回答