leigepython

Python 获取windows管理员权限办法

from __future__ import print_function
import ctypes, sys, os


def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False
    
if is_admin():
    os.startfile("system-jg_new.exe")
else:
    if sys.version_info[0] == 3:
        ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
        os.startfile("system-jg_new.exe")
    else:  # in python2.x
        ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1)
View Code

 

分类:

技术点:

相关文章:

  • 2021-06-18
  • 2021-08-18
  • 2021-04-14
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2021-12-15
  • 2021-11-20
  • 2021-10-25
  • 2021-12-01
  • 2021-11-20
相关资源
相似解决方案