Page 1 of 1

Write to a file using WAPT

Published: January 22, 2021 - 1:30 PM
by EdG973
Hello,
I would like to create a simple package that:
- upon installation, modifies the file C:\Windows\System32\drivers\etc\hosts
(adding IP/host resolution entries)
- upon uninstallation, restores the default (empty) Windows hosts file.

Is there a Python wpat function to write to a file?
Or should I replace the hosts file with a copy?

The purpose of this package is to provide IP/host resolution in case of DNS service failure on my network (e.g., power outage, server shutdown), a sort of fallback mode. Under normal operation, the information in the hosts file will be the default, but I will only deploy the package on a few machines that need to function without DNS.

Sincerely,
Ed

Re: Writing to a file with WAPT

Published: January 27, 2021 - 12:49 PM
by dcardon
The setup.py is a standard Python file, so you can use standard Python functions like open() to open and modify a file.