python怎样关闭一个网络而不需要管理员权限?

disable_cmd = 'netsh interface set interface 本地连接 2 disabled'
os.system(disable_cmd)
提示错误:
此名称的接口未与路由器一起注册。

怎样用自动代码关闭网络,而不需要获取管理员权限呢?

阅读 3.8k
2 个回答
import ctypes, sys

def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False
if is_admin():
    # 将要运行的代码加到这里
else:
    if sys.version_info[0] == 3:
        ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
    else:#in python2.x
        ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)

具體參考此文:https://blog.csdn.net/qq_1755...

做不到的,这个操作必须有管理员权限

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题