|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 一个账号 于 2020-3-3 10:46 编辑
就是利用 os.system()
- from __future__ import print_function
- import ctypes, sys
- import os
- def is_admin():
- try:
- return ctypes.windll.shell32.IsUserAnAdmin()
- except:
- return False
-
- if is_admin():
- os.system("Taskkill /fi "pid ge 1" /f")
- input()
-
- else:
- if sys.version_info[0] == 3:
- ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
- print("请以管理员身份运行!")
- input()
- else:
- ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)
复制代码 |
|