akroy akroy - 6 months ago 88
C# Question

Host name resolution without modifying the hosts file

I'm trying to figure out how if there's a way to make a hostname resolve to a certain IP without DNS or host file modification.

Using C#, I'm making a request from client to server, but I have to use the hostname in the request so that the certificates will properly authenticate the request. However, my program is meant to run without admin rights, so I can't modify the host file. I have the correct IP and the host name, is there any other way to make the computer resolve the host name to the IP?


It looks like the simplest way to solve this is to create a service with the rights to modify the host file, then invoke that service from the main program. The service runs a single command and exits. Since a service can have elevated status, you can essentially encapsulate admin rights inside a standard user program.