* Conoscenza del computer >> Computer >  >> Social media

Modificare il file hosts su Windows 10: risolvere l'errore 'Accesso negato' anche da amministratore

Why this happens

`C:\Windows\System32\drivers\etc\hosts` is a **protected system file**. Even Admin accounts need **elevated token** (UAC) + **Write DACL** on file. Default: `Administrators: (R, RX)` only. `SYSTEM: F`, `TrustedInstaller: F`.

Fixes (easiest → hardest)

1. Run Editor **As Administrator** (90% of cases)

  1. Close all Notepad/editor instances.
  2. Start → Type **Notepad** → Right-click → **Run as administrator** → Yes (UAC).
  3. File → Open → `C:\Windows\System32\drivers\etc\` → Bottom right "Text Documents" → **All Files** → Select `hosts` → Open.
  4. Edit → Save. **Works if UAC prompt accepted and AV not blocking.**

2. Check/Fix File Permissions (if #1 fails)

  1. Explorer → `C:\Windows\System32\drivers\etc\` → Right-click `hosts` → Properties → **Security** tab.
  2. Group/Users: Select **Administrators** (or your user) → **Edit** → Select Administrators → **Allow: Full Control** → OK → OK.
  3. If "Add" needed: Add "Administrators" → Check Names → OK → Full Control.
  4. Retry #1.

3. Temporarily Disable UAC (not recommended, but diagnostic)

  1. Start → "UAC" → **Change User Account Control settings** → Slider to **Never notify** → OK → **Reboot**.
  2. Try edit hosts (still run editor admin for consistency).
  3. **Immediately move slider back to default (2nd notch) → Reboot.**

4. Antivirus / Endpoint Protection Blocking

  • Some AV (Bitdefender, Kaspersky, CrowdStrike, Defender ATP) **lock hosts** to prevent hijack.
  • **Pause protection** (5-15 min) → Edit hosts → **Re-enable**.
  • Or add **exclusion** for `C:\Windows\System32\drivers\etc\hosts` in AV settings.

5. SFC / DISM (system file corruption)

# Admin CMD / PowerShell
sfc /scannow
DISM /Online /Cleanup-Image /RestoreHealth
# Reboot → Try #1 again.

6. Take Ownership (Last resort)

  1. hosts Properties → Security → Advanced → **Owner: TrustedInstaller** → Change → Type **Administrators** → Check Names → OK → **Check "Replace owner on subcontainers and objects"** → Apply.
  2. Now Administrators own it → Edit Permissions (Step 2) → Full Control → Apply.
  3. Edit via Admin Notepad.
  4. **Optional:** Return ownership to TrustedInstaller (repeat step 1 with TrustedInstaller).

Common Hosts Entries (for reference)

# Block domain
127.0.0.1   analytics.google.com
0.0.0.0     ads.example.com

# Local dev mapping
127.0.0.1   myapp.local
192.168.1.50   server.internal
  • **Encoding:** Save as **ANSI** (Notepad default) or **UTF-8 without BOM**. Not UTF-16.
  • **No extension.** File name exactly `hosts`.
  • **Flush DNS after edit:** `ipconfig /flushdns` (Admin CMD).

Malware Alert

If you **didn't edit it** and see unknown entries (banking sites → 127.0.0.1, or strange IPs) → **Malware modified hosts**. Run full scan (Malwarebytes + Defender Offline).

Bottom line: Run Notepad **as Administrator** + ensure **Administrators have Full Control** on file = fixes 99%. If AV blocks → exclude path.

Social media

  • --热点Computer