This portion of the tutorial demonstrates the procedure for deploying the Python script at system start-up, eliminating the necessity to manually open the terminal each time to execute the script.
Steps for Script Deployment on Windows
To automate deployment on Windows, it is essential to adhere to the following procedures:
Changing the Hosts File Path on Windows
First, let’s modify the path of our hosts file from "/etc/hosts" to "C:\System32\drivers\etc\hosts," since this is where the hosts file is located on Windows systems.
Opening Windows Task Scheduler
To schedule tasks on Windows, it is necessary to launch the Task Scheduler, as illustrated in the image below.
Creating a New Task
Select the Create Task option located in the right pane of the application.
The following window will open.
Configuring Task Properties
Set the properties and assign a name along with any other essential attributes for your script. Ensure to select the checkbox labeled "Run with highest privileges."
Setting the Startup Trigger
Navigate to the Triggers section and establish a new trigger as illustrated in the image below.
Choose the "At startup" option from the dropdown menu to ensure that the script executes during the startup process.
Adding Script Action
Next, navigate to the Actions section and initiate the creation of a new action by selecting the 'new' option.
The subsequent window will appear. From the drop-down menu, choose the action labeled "Start a program" and navigate to the location of the script, for instance, blocker.py (in my scenario, it is located at E:\blocker.py). After that, click OK.
Configuring Task Conditions
Next, navigate to the Conditions section and uncheck the second option that states, "Start the task only if the computer is on AC power."
Final Task Settings
Next, navigate to the settings and select OK, as illustrated in the image below.
Verifying the Scheduled Task
At this point, we have successfully configured our task named Website-blocker to initiate at system startup. We can verify this by examining the task list, as depicted in the image below.
Restarting and Testing the Script
At this point, it is necessary to reboot our system in order to enable the script to run automatically during the system's startup process.
Please reboot the system at this moment, and attempt to reach the restricted website www.facebook.com since we are currently within working hours.
The display will appear as follows.
Conclusion
As a result, our script is successfully operational during system startup, and it effectively restricts access to www.facebook.com (or any other website of your choice) automatically.