Missing Hosts Entry. User did not grant permission. Windows 10

Hi, when I install a new site, I get a Windows notification message in the bottom right corner that says “Local is requesting administrative privileges to modify your /etc/hosts file”. However, the UAC dialog box never appears. And then I see this in the log file:

{"thread":"main","class":"HostsFileService","level":"info","message":"Updating hosts with","timestamp":"2020-05-08T21:02:26.085Z"}
{"thread":"main","class":"HostsFileService","error":{"message":"User did not grant permission.","stack":"Error: User did not grant permission.\n    at G:\\Program Files\\Local\\resources\\app.asar\\node_modules\\sudo-prompt\\index.js:534:29\n    at ChildProcess.exithandler (child_process.js:315:5)\n    at ChildProcess.emit (events.js:203:13)\n    at maybeClose (internal/child_process.js:1021:16)\n    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)"},"level":"error","message":"Could not update hosts.","timestamp":"2020-05-08T21:02:26.962Z"}

A similar thing happens when I try to set up a SSL certificate. After clicking on “TRUST”, a notification appears in the bottom right hand corner saying “local is requesting administrative privileges to trust a certificate” but again, the UAC prompt never appears. And this is recorded in the log file:

{"thread":"main","reason":{"error":{}},"p":{},"level":"warn","message":"Unhandled Rejection.","timestamp":"2020-05-09T03:15:00.532Z"}

It seems that for some reason, the call to sudo-prompt is failing. I have found a number of similar posts on here and have followed all the proposed solutions:

  • make sure read flag is not set on the hosts file
  • check if there is anti-virus that may be locking the file
  • disable firewalls
  • run Local in administrative mode

I have also tried clean installing different versions of Local(5.2.8, 5.3.3, 5.4.1, 5.4.2), installing different versions of nodejs and restarting the computer to clear any lingering processes but nothing seems to work.

I’m not sure what else to try so I was wondering if anyone else has found a solution? Any help would be greatly appreciated. Thanks.

Hi Bryan,

Sorry about this!

Do you have any anti-virus outside of Windows Defender? I’m curious if the elevate helper for sudo-prompt is getting quarantined.

Hey Clay, thanks for getting back to me. I only have Windows Defender and even when I disable it, the problem still occurs. Also, Defender will normally show a notification whenever it finds a threat and as far as I know, there weren’t any notifications regarding sudo-prompt. There’s also no record of anything related to sudo-prompt in the protection history.

I’ve been thinking, maybe it’s a bug in Windows 10? I’ve seen a number of articles about bugs in recent Windows updates. I assume you guys have Local installed and working properly on a Windows 10 machine. Could you tell me what version of Windows it’s running? Maybe I can try switching to that version and see if that fixes the problem. I’m currently using version 1903 (os build 18362.778). Thanks.

Hi, so I tried installing the latest version (5.5.2) but the problem is still there. Local can’t edit the hosts file. I know I’m not the only one having this problem… just search this forum for “hosts file” (https://localwp.com/community/search?q=hosts%20file) and you’ll see that this is an ongoing problem that goes back a number of years.

After reading all the posts on here, it seems that the problem is related to my particular setup. A combination of the hardware and software that I have on my machine. Unfortunately, I am unable to isolate what is locking up the hosts file. Or preventing the UAC prompt from showing. What’s interesting is that I have tested a different development tool, which works similar to Local, but that tool is able to bring up the UAC prompt and automatically edit the hosts file with no problems. So if they can access the hosts file, why can’t Local? It’s too bad because Local’s UI is way better.

Hey, so I finally got it working and I just wanted to give an update in case it might help anyone else having the same problem.

It turns out that if I have batch files (.bat) associated with any program, then the UAC prompt won’t come up and Local won’t be able to edit the hosts file. In my case, I had the .bat extension associated with a program called notepad++. Once I removed the association, Local worked fine. When I added the association back, Local would stop working again. I’m not sure why it behaves like this but maybe @clay or the dev team can have a look to see if this is something they can patch?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.