How to open command prompt in Administrator mode in python?
from pynput.keyboard import Key, Controller
import time
keyboard = Controller()
keyboard.press(Key.cmd)
keyboard.release(Key.cmd)
time.sleep(0.3)
keyboard.type("cmd")
time.sleep(1)
keyboard.press(Key.right)
keyboard.release(Key.right)
keyboard.press(Key.down)
keyboard.release(Key.down)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(0.5)
keyboard.press(Key.tab)
keyboard.release(Key.tab)
keyboard.press(Key.tab)
keyboard.release(Key.tab)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
exit
Related videos on Youtube
IcanCwhatUsay
Updated on June 04, 2022Comments
-
IcanCwhatUsay almost 2 years
I'm a bit of a noob, so sorry in advance if I'm not doing this right.
I'm using python 3.6x
What I have so far that gets the command window open is
import os os.open("start cmd")
but this comes up in the directory that I'm working from and not in administration mode.
I've also tried
import os os.system("start /wait cmd /wait {tskill dwm}")
but that didn't work either. (
tskill dwm
is what I'm trying to get python to write in to command manager to fix a bug with windows' buttons not going away)My overall goal is to just click this python script
Blah.py
and have it restart the windows viewer or whatever it's called. Doing this clears the stuck buttons. Overall this is just an exercise in practicing python. I know I could just disable the button fade out and that would take care of the issue. I just figured this would be a good learning opportunity.-
ewcz about 6 yearsPossible duplicate of open cmd with admin rights (Windows 10)
-
Evtim Kostadinov over 2 yearsDoes this answer your question? Request UAC elevation from within a Python script?
-