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.

3
  • 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 Commented May 16, 2013 at 3:41
  • this post has some insight : stackoverflow.com/questions/130763/… Commented May 16, 2013 at 3:47
  • Honestly, If possible don't use python for this task - powershell could do this better, it is designed for this kind of task Commented Jul 2, 2017 at 14:52

1 Answer 1

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'])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.