是否可以将此命令配置为不显示以管理员身份运行的是/否(UAC)?

问题描述 投票:0回答:1

是否可以将此命令配置为不显示是/否(UAC 是否允许此应用程序对您的设备进行更改?)以管理员身份运行?直走还是让它不出现?

命令:

import pyuac
from pathlib import Path
import shutil

def main():
    print("Do stuff here that requires being run as an admin.")
    dir_path = Path('C:/Users/RIEIDI~2/AppData/Local/Temp')
    for file_path in dir_path.iterdir():
        try:
            if file_path.is_dir():
                shutil.rmtree(file_path)
            else:
                file_path.unlink()
        except OSError:
            print(f"Error deleting {file_path}")
    input("Press enter to close the window. >")

if __name__ == "__main__":
    if not pyuac.isUserAdmin():
        print("Re-launching as admin!")
        pyuac.runAsAdmin()
    else:
        main() 

找了很多都没找到

python windows admin temporary-files
1个回答
0
投票

您可以要求程序从一开始就以管理员身份运行,方法是使用

right-click
>
Run as Administrator
.

© www.soinside.com 2019 - 2024. All rights reserved.