拒绝访问主机文件 [英] Access denied to hosts file

查看:124
本文介绍了拒绝访问主机文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Visual Studio中运行我的程序时,它在没有管理员权限的情况下完美运行。但是当我使用.exe文件运行程序时出错 - 访问路径C:/ Windows / System32 / drivers / etc / host



这是我的代码 - < br $>


 Dim文件As System.IO.StreamWriter 
file = My.Computer.FileSystem.OpenTextFileWriter( C:/ Windows / System32 / drivers / etc / hosts,True)
file.WriteLine( 127.0.0.1 + www.google.lk)
file.Close()





我尝试了什么:



试运行作为管理员

在app.manifest文件中将asInvoker更改为highestAvailable

尝试授予访问权限

解决方案

< blockquote>该文件受Windows保护。您需要管理员权限。可能,你必须在写入之前删除一些像只读的标志。

另请注意,当应用程序尝试写入不必执行此操作的位置时,Windows使用虚拟化。看看C:\ Users \Your.Username \ AppData \ Local \ VirtualStore。

顺便说一下, file.WriteLine(127.0.0.1 + www.google.lk)可能有误,我想它应该是 file.WriteLine(127.0.0.1 www.google.lk)如果您想将对sri lankan google网站的任何调用重定向到localhost。


When I run my program in Visual Studio it works perfectly without admin privileges. But when I run program using .exe file error occurred - Access to path "C:/Windows/System32/drivers/etc/host"

Here's my code -

Dim file As System.IO.StreamWriter
               file =    My.Computer.FileSystem.OpenTextFileWriter("C:/Windows/System32/drivers/etc/hosts", True)
               file.WriteLine("127.0.0.1 " + www.google.lk)
               file.Close()



What I have tried:

Tried running as Administrator
Change "asInvoker" to "highestAvailable" in app.manifest file
Tried giving access permission

解决方案

That file is protected by Windows. You need Admin permissions. Likely, you have to remove some flags like read-only before you can write to it.
Also note that Windows uses "virtualization" when an application tries to write where it must not do so. Take a look at C:\Users\Your.Username\AppData\Local\VirtualStore.
By the way, file.WriteLine("127.0.0.1 " + www.google.lk) is likely wrong, I guess it should be file.WriteLine("127.0.0.1 www.google.lk") if you want to redirect any calls to the sri lankan google site to localhost.


这篇关于拒绝访问主机文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆