简体   繁体   English

如何以编程方式阻止应用程序读取计算机文件?

[英]How would one programmatically stop an app from reading computer files?

In a language like Python for scripting, how would you stop an app from having access to reading computer files, especially sensitive system-level ones?在像 Python 这样用于脚本的语言中,您将如何阻止应用程序读取计算机文件,尤其是敏感的系统级文件?

Edit: To be clear, I mean set permissions for that app to not have access to computer files, even after the script is done running (setting permissions).编辑:要清楚,我的意思是将该应用程序设置为无权访问计算机文件,即使在脚本运行完成后(设置权限)也是如此。

You should run your python script as a non-privileged user and read a file after validating the access您应该以非特权用户身份运行 python 脚本并在验证访问权限后读取文件

# check readability of the path 
if os.access("file.txt", os.R_OK):  
    # open txt file as file 
    with open("file.tx") as file: 
        return file.read() 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为了让一个用户通过网站从其他用户计算机下载文件,我需要编码什么? - What would I need to code in order for one user to download files from another users computer, through a website? 从文件读取时计算一行中有多少个“/” - Count how many of '/' are in one line while reading from files 如何使用 WMI 和 Python 从远程计算机复制文件并将它们存储在本地计算机中? - How to copy files from remote computer and storing them in local one using WMI and Python? 执行一次后如何停止if循环? - How would I stop a if loop after execute one time? 读取一个文件夹中的所有文件后,如何在python中从一个文件夹跳转到另一个文件夹? - How to jump from one folder to another folder in python after reading all the files in one folder? 您将如何按文件类型将文件从一个目的地移动到另一个目的地? - how would you move files from one destination to another sorted by file type? 从python中的一个目录中一一读取视频文件 - Reading video files one by one from a directory in python 如何使用python脚本将文件从客户端传输到服务器计算机? - How to Transfer Files from Client to Server Computer by using python script? 如何让我的电脑从 email 下载.py 文件 - How to allow my computer to download .py files from an email 如何使用 django 从客户端计算机中删除本地文件 - how to delete local files from client computer with django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM