python 基础之管理员权限执行的操作

目录

  • 非管理员运行python报错如下
  • 以管理员权限执行的操作

非管理员运行python报错如下

Traceback (most recent call last): File
“D:\Python36\lib\site-packages\pywinauto\application.py”, line 1047,in start
start_info) # STARTUPINFO structure. pywintypes.error: (740, ‘CreateProcess’, ‘请求的操作需要提升。’)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
“C:\Users\EDZ\eclipse-workspace\YZEPR\com\zdh\main.py”, line 6, in app = Application(backend = “uia”).start(r"D:\XXXX.exe") File
“D:\Python36\lib\site-packages\pywinauto\application.py”, line 1052, in start
raise AppStartError(message) pywinauto.application.AppStartError: Could not create the process “D:\APS\ERP_KHD_V9.2.1_V1.0.0\YZERP.exe”
Error returned by CreateProcess: (740, ‘CreateProcess’, ‘请求的操作需要提升。’)

以管理员权限执行的操作

import ctypes, sys
import os
def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False
if is_admin():
    # 这里写入需要管理员权限执行的操作
    app = Application(backend = "uia").start(r"D:\XXXX.exe")
    pass
else:
    if sys.version_info[0] == 3:
        ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)

你可能感兴趣的:(#,python基础)