Question File access error?

Jun 23, 2019
8
0
10
So, I'm trying to run this aplication that needs to write stuff to the hosts file and it seems like the aplication can't find or access this file.

Log:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

** Exception Text **
System.IO.FileNotFoundException: Could not find file 'C:\WINDOWS\system32\drivers\etc\hosts'.
File name: 'C:\WINDOWS\system32\drivers\etc\hosts'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
at System.IO.StreamReader..ctor(String path, Encoding encoding)
at System.IO.File.ReadAllLines(String path, Encoding encoding)
at ‌‌‏‭‍‭‏‬‎‎‌‭‌‫‬‭‮.get_HasHostsfileEntry()
at ‌‌‏‭‍‭‏‬‎‎‌‭‌‫‬‭‮.‍‌‎‎‏‫‭‬‍‫‮‬‭‎‮‫‮‌‫‪‌‬‪‭‫‮()
at ‌‌‏‭‍‭‏‬‎‎‌‭‌‫‬‭‮.‍‪‎‫‬‌‬‮‪‮‪‫‪‪‌‮‏‎‬‮(Object , EventArgs )
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


** Loaded Assemblies **
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.8941 (WinRelRS4.050727-8900)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.8922 (WinRelRS4.050727-8900)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.8941 (WinRelRS4.050727-8900)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.8922 (WinRelRS4.050727-8900)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.8922 (WinRelRS4.050727-8900)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.8922 (WinRelRS4.050727-8900)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------

** JIT Debugging **
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Any help is appreciated.
 
your application must be "Run as Administrator" to edit this file
or add/change permissions through 'Properties->Security' tab to allow full control without admin rights
file-security-tab.jpg
 
try making 'hosts' read\write permitted for everyone, remove permissions inheritance.

can't think of any other reason besides the file being already accesses=busy, or permissions block

the program itself that gives you this message may be a program that locks the file. Make sure you practice good housekeeping by shutting down each data stream after using it.
 
Jun 23, 2019
8
0
10
try making 'hosts' read\write permitted for everyone, remove permissions inheritance.

can't think of any other reason besides the file being already accesses=busy, or permissions block

Thanks for your help, sadly that didn’t help either I’m beginning to think that it’s not something to do with the hosts file but with the registry entries which it’s also trying to edit.