从 .net 4 c# 中解锁文件
是否有可能解锁从 ac# 程序中从互联网下载的文件。 上网冲浪后我了解到,该信息被写入 (NTFS) 文件的替代流中,其中包含当前区域信息(值 3 来自互联网,被解释为被阻止)。
是否有管理的可能性来清除或更改文件的区域信息(取消阻止),或者是否有管理复制功能可以复制没有区域信息的文件? 如果没有,我该如何使用 PInvoke 但不包含外部程序集(我不允许在当前项目中执行此操作)。
Is there a possibility to unblock a file that is downloaded from the internet from within a c# program.
Surfing the internet I have learned, that the information is written in an alternative stream of a (NTFS) file that contains the current zone information (value 3 is from the internet and is interpreted as blocked).
Is there a managed possiblity to either clear or change the zone information (unblock) of a file or is there a managed copy function that copies the files without the zone information?
If not, how can I do with PInvoke but without including a foreign assembly (I'm not allowed to do this in a current project).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
根据您的输入,我完成了以下代码:
感谢 Stuart Dunkeld、Alex K(+1) 和 Sven 为我指明了方向。
更新
我已在此处发布了代码,以获取其在生产中是否可靠工作的反馈环境。如果有人想使用它,请查看那里。
Based on your input I have done the following code:
Thanks to Stuart Dunkeld, Alex K(+1) and Sven to show me the direction.
UPDATE
I have posted the code here for a feedback if it would work reliable in production environment. If someone want to use it, check out there.
它存储在
:Zone.Identifier
流中 (more < c:\theapp.exe:Zone.Identifier
),您需要使用本机 IO 例程来操作它们,这是一个托管包装。It's stored in the
:Zone.Identifier
stream (more < c:\theapp.exe:Zone.Identifier
) you need to use the native IO routines to manipulate them, here is a managed wrapper.管理此标识符的官方方法是使用 PersistentZoneIdentifier COM 对象: http://msdn.microsoft.com/en-us/library/ms537029(v=vs.85).aspx
The official way to manage this identifier is with the PersistentZoneIdentifier COM object: http://msdn.microsoft.com/en-us/library/ms537029(v=vs.85).aspx
我正在使用 .net 7,我发现它们做了同样的事情。
解除阻止:
阻止:
I'm using .net 7, I've found these does the same thing.
Unblock:
Block:
如果您只想取消阻止文件,请使用 powershell 命令:
将目录更改为包含文件的文件夹并运行该命令。参数-r是列出所有子文件夹中的文件。
If all you want is to unblock files use a powershell command:
change directory to the folder containing the files and run that command. The parameter -r is to list files in all sub-folders.