Cross-platform way to check admin rights in a Python script under Windows?

前端 未结 5 1688
傲寒
傲寒 2021-02-01 18:57

Is there any cross-platform way to check that my Python script is executed with admin rights? Unfortunately, os.getuid() is UNIX-only and is not available under Win

5条回答
  •  不要未来只要你来
    2021-02-01 19:56

    import ctypes, os
    try:
     is_admin = os.getuid() == 0
    except AttributeError:
     is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
    
    print is_admin
    

提交回复
热议问题