How do I write to a protected/system file on Windows runners?

I need to append text to my C:\Windows\System32\drivers\etc\hosts file on a Windows runner (ideally using bash). How can I do this, as the file is only writeable by administrators? sudo is not installed on the VMs.

GitHub-hosted runners use an administrator account:

Windows virtual machines are configured to run as administrators with User Account Control (UAC) disabled.

I was able to append to the hosts file, but I had no luck getting any effect out of it (tested with a Python web server running in the background):

run: |
  echo '' >> 'C:\Windows\System32\drivers\etc\hosts'
  ipconfig /flushdns
  nbtstat -R

Maybe Curl does its own DNS resolution? Or it’s another problem with the DNS cache. I tried adding

  net stop dnscache
  net start dnscache

but this isn’t allowed on the GitHub-hosted runners it seems:

The requested pause, continue, or stop is not valid for this service.
More help is available by typing NET HELPMSG 2191.

The requested service has already been started.
More help is available by typing NET HELPMSG 2182.