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

前端 未结 5 1619
傲寒
傲寒 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:48

    It's better if you check which platform your script is running (using sys.platform) and do a test based on that, e.g. import some hasAdminRights function from another, platform-specific module.

    On Windows you could check whether Windows\System32 is writable using os.access, but remember to try to retrieve system's actual "Windows" folder path, probably using pywin32. Don't hardcode one.

提交回复
热议问题