def elevate_to_system()

in cortado/rtas/_common.py [0:0]


def elevate_to_system(arguments: list[str] | None = None) -> bool:
    if is_system():
        return True

    arguments = arguments or get_current_exec_args()
    ps_exec_path = get_resource_path(PS_EXEC_EXE)

    log.info("Attempting to elevate to SYSTEM using PsExec")

    if not ps_exec_path.is_file():
        log.error("PsExec not found")
        raise ExecutionError(f"PsExec not found at `{ps_exec_path}`")

    returncode, _, _ = execute_command([str(ps_exec_path), "-w", os.getcwd(), "-accepteula", "-s"] + arguments)

    if returncode == ACCESS_DENIED_RETURNCODE:
        log.error("Failed to elevate to SYSTEM")
        return False

    return True