我正在尝试使用 Python 3.7 pyautogui 以管理员身份打开 CMD。我可以导航到开始菜单图标,输入“cmd”并按 ctrl + shift +enter 以在管理模式下打开 cmd。
然后会出现一条弹出消息,提示是否以管理员身份打开。当我使用 pyautogui.press('left') 时,它没有按下左按钮。
try:
import pyautogui
import time
pyautogui.FAILSAFE = True
pyautogui.PAUSE = 0.5
mouseMovementDuration = 2 #every mouse movement will take 2 secs
intervalBetweenKeyPress = 0.5
def runCMDasAdmin():
x, y = pyautogui.locateCenterOnScreen(r'C:\\Users\\Saru\\Desktop\\PyAutoGUI\\images\\startmenu.png')
pyautogui.click(x=x, y=y,button='left',duration=mouseMovementDuration)
pyautogui.typewrite('cmd', interval=intervalBetweenKeyPress)
pyautogui.hotkey('ctrl', 'shift', 'enter')
pyautogui.press(['left','enter'],interval=intervalBetweenKeyPress)
print(pyautogui.size()) #It will give you the size of the screen
pyautogui.moveTo(x=1919,y=1079,duration=mouseMovementDuration)
pyautogui.moveTo(x=1,y=1,duration=mouseMovementDuration)
runCMDasAdmin()
except Exception as e:
print("Exception Raised------>",str(e))
我想使用 pyautogui 以管理员身份打开 cmd。请帮忙。
最佳答案
由于用户访问控制 (UAC) 提示在一个单独的层上工作,超出了任何自动化/代码组件的控制范围,以保证用户的安全。所以唯一的解决办法就是完全禁用UAC提示。禁用 UAC 提示的过程 - 在开始菜单中键入 UAC,选择用户访问控制设置,将其设置为从不通知。
关于python - 无法使用 Python Pyautogui 以管理员身份打开 CMD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54540047/