PSHostsFile icon indicating copy to clipboard operation
PSHostsFile copied to clipboard

Host file not found

Open qadeemakhtar opened this issue 7 years ago • 2 comments

image I am facing this exception on some user side @fschwiet please help

qadeemakhtar avatar Apr 03 '17 04:04 qadeemakhtar

Does the file exist, or is it in another location?

Here is the code that expects to find the file:

    public static string GetHostsPath()
    {
        var systemPath = Environment.GetEnvironmentVariable("SystemRoot");
        var hostsPath = Path.Combine(systemPath, "system32\\drivers\\etc\\hosts");

        if (!File.Exists(hostsPath))
            throw new FileNotFoundException("Hosts file not found at expected location.");
        return hostsPath;
 }

If the file does not exist, then I suggest creating it. I don't know your platform, so I suppose you'll need to check that the OS uses the file at that location.

fschwiet avatar Apr 03 '17 14:04 fschwiet

@fschwiet WOW64 redirection can lead a 32 bit application to report such exceptions on a Windows x64 machine. You should modify your library to better work that scenario,

https://stackoverflow.com/questions/25908033/how-to-get-64bit-system-folder-in-a-32bit-application

lextm avatar Jan 26 '20 02:01 lextm