是否可以将此命令配置为不显示是/否(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()
找了很多都没找到
您可以要求程序从一开始就以管理员身份运行,方法是使用
right-click
> Run as Administrator
.