One , What will be done cmd Command in the xx.bat In the document
Two , establish shell.vbs Make the system run with administrator privileges
cwd = CreateObject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
path = cwd & "\RestartInternet.bat"
Set shell = CreateObject("Shell.Application")
shell.ShellExecute path,"","","runas",1
WScript.Quit
3、 ... and ,python call
# !/usr/bin/python3
# coding: utf-8
import os
import subprocess
import traceback
def runAdmin(cmd, timeout=1800000):
# This paragraph is to be executed cmd Command write .bat, If you have already created .bat, Then this paragraph can be commented out
f = None
try:
bat = os.getcwd() + r"\RestartInternet.bat"
f = open(bat, 'w')
f.write(cmd)
except Exception as e:
traceback.print_exc()
raise e
finally:
if f:
f.close()
try:
shell = os.getcwd() + r"\shell.vbs"
sp = subprocess.Popen(
shell,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
print("[PID] %s: %s" % (sp.pid, cmd))
sp.wait(timeout=timeout)
stderr = str(sp.stderr.read().decode("gbk")).strip()
stdout = str(sp.stdout.read().decode("gbk")).strip()
if "" != stderr:
raise Exception(stderr)
if stdout.find(" Failure ") > -1:
raise Exception(stdout)
except Exception as e:
raise e