I've been trying to modify the hosts file in Windows using C# .NET windows desktop app, but no matter what I try, I always get the error
Access denied
Access denied
even though I do run my code as admin.
I've tried : 1. manually opening the hosts file and writing to it 2. running a cmd script as admin (that usually works when manually ran) but it didnt work when I called it from my code 3. running a ps script (that also works when ran manually) but didn't work when ran inside my c# code.
So how can I do this..? Seems like I just can't modify the hosts file at all in C# even with admin privileges