0

I want to run a script on the admin cmd prompt using python os.system

import os
import sys
import keyboard
import time

os.system('cls')
print('+'* 60)
os.system('netsh wlan set hostednetwork mode=allow ssid=test3 key=987654321')
time.sleep(2)
p = input('')
keyboard.press_and_release('enter')
print('@' * 60)
os.system('netsh wlan start hostednetwork')
time.sleep(2)
keyboard.press_and_release('enter')
v = input('')

How can I call the admin cmd prompt ?

Thank you in advance

  • 4
    Possible duplicate of [How to run cmd command in Python with admin](https://stackoverflow.com/questions/25557921/how-to-run-cmd-command-in-python-with-admin) – Selcuk Sep 24 '19 at 22:54
  • first of all thank you for your suggestion, but the code out there works only to popup admin window, it doesn't execute the given command I've tried import win32com.shell.shell as shell commands = 'ipconfig' shell.ShellExecuteEx(lpVerb='runas', lpFile='cmd.exe', lpParameters='/c '+commands) – Golden Monkey Sep 24 '19 at 23:06
  • 1
    didn't find a thing through your shared question, check out my answer here, I solve the problem using batch file.. and thank you so much – Golden Monkey Sep 25 '19 at 00:11

1 Answers1

0

I found a way to make this happen so my idea is to to create script to share wifi using python, and the problem is you have to execute the script using admin command prompt. and to solve that, follow my steps:

1 - create the python script for the commands(copy mine in the original question) 2 - create a simple text file like this one

pause 
python name.py
pause

3 - save it under the extension of " .bat " (example.bat) 4 - go to your system directory (mine is "C:\Windows\System32") 5 - copy the the batch file there 6 - create a shortcut for this batch file (it will ask to be in your desktop, click OK) 7 - go to the properties of this shortcuted file click on advanced and give it the admin access - click OK 8- copy or cut your script.py file to the same directory (mine is "C:\Windows\System32")

and that's it, just launch your batch file in the desktop and here you go everything works fine.