Hrishi
Hrishi

Reputation: 51

Accessing the Host File In A Python Program

I created a program which modifies the hosts file in order to block some websites. But when I am running the programme, I am getting this error. Btw I have created my Python file using Pycharm IDE and my intention is to run this script everytime open my PC using Task Scheduler. So please kindly do tell me what I should be running as the administrator. Is it like the Pycharm itself? Most importantly how do I give it Admin permissions permanently?

[Errno 13] Permission denied: 'C:\\Windows\\System32\\drivers\\etc\\hosts'

Please kindly tell me a way to fix this.

Upvotes: 0

Views: 662

Answers (1)

Vishal Bakshi
Vishal Bakshi

Reputation: 121

On Windows create a scheduled task on logon, and configure the task to run under a system account. The task could simply be run as a batch file and within the batch file you may run the below command. Ensure the task is set to run with administrator privileges in the task creation window

C:\PythonFolder\python.exe yourscript.py

Upvotes: 2

Related Questions