Python:如何以管理员权限启动进程? [英] Python: How to start a process with Administrator Permissions?

查看:58
本文介绍了Python:如何以管理员权限启动进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从具有管理员权限的 Windows 7 命令行启动以下脚本:

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")

我还在属性">兼容性">权限级别"下为 python.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?

提前感谢您的帮助!

干杯 -

推荐答案

我无法使用 Vista 或 Windows 7,但您应该能够使用 runas代码>命令.

I don't have access to Vista or Windows 7, but you should be able to use the runas command.

import subprocess
subprocess.call(['runas', '/user:Administrator', 'C:/my_program.exe'])

这篇关于Python:如何以管理员权限启动进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆