Unblock File from within .net 4 c#

﹥>﹥吖頭↗ 提交于 2019-11-26 22:06:09

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.

HCL

Based on your input I have done the following code:

public class FileUnblocker {
    [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool DeleteFile(string name);

    public bool Unblock(string fileName) {
        return DeleteFile(fileName + ":Zone.Identifier");
    }
}

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!