6

in python, i want to executes cmd command:

os.system("netsh interface set interface \"Local Area Connection\" disable")

to disconnect internet network. But, with my account, it report, interface name not register router. I think that, i need to executes os.system as admin. But i don't know how to use it as admin! So, can you help me! Thank.

Dual Core
  • 99
  • 1
  • 1
  • 5
  • an easy way is to make an executable with pyinstaller and the --onefile option. once the exe is created rename it... it will now require admin to run – Joran Beasley May 16 '13 at 03:41
  • this post has some insight : http://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script – Joran Beasley May 16 '13 at 03:47
  • Honestly, If possible don't use python for this task - powershell could do this better, it is designed for this kind of task – Christian Sauer Jul 02 '17 at 14:52

1 Answers1

2

To run command as admin on Windows, ou can use Windows runas command (I don't have access to a Windows machine right now, but perhaps..);

import subprocess
subprocess.call(['runas', '/user:Administrator', 'Your command'])