我的问题与大多数人相反。我正在用 C# 本地生成文件,但是我want将它们标记为已阻止。因此,当用户在 Word 或 Excel 等应用程序中打开它们时,它会在“保护模式”下打开它们。
I've read http://answers.microsoft.com/en-us/windows/forum/windows_xp-security/security-this-file-came-from-another-computer-and/56ccf19c-66e8-4280-8588-8c91e5d436bf这是在“NTFS 备用数据流”上设置的。有谁知道我如何在 C# 中模仿这个?
您还可以使用保留区域标识符 http://msdn.microsoft.com/en-us/library/ms537029%28v=vs.85%29.aspx对象而不是直接写入替代数据流。
更多信息请点击这里:http://blogs.msdn.com/b/oldnewthing/archive/2013/11/04/10463035.aspx http://blogs.msdn.com/b/oldnewthing/archive/2013/11/04/10463035.aspx和这里:https://github.com/citizenmatt/UnblockZoneIdentifier https://github.com/citizenmatt/UnblockZoneIdentifier
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
namespace ConsoleApplication3
{
public enum URLZONE : uint
{
URLZONE_LOCAL_MACHINE = 0,
URLZONE_INTRANET = 1,
URLZONE_TRUSTED = 2,
URLZONE_INTERNET = 3,
URLZONE_UNTRUSTED = 4,
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("cd45f185-1b21-48e2-967b-ead743a8914e")]
public interface IZoneIdentifier
{
URLZONE GetId();
void SetId(URLZONE zone);
void Remove();
}
class Program
{
static void Main(string[] args)
{
object persistZoneId = Activator.CreateInstance(Type.GetTypeFromCLSID(Guid.Parse("0968e258-16c7-4dba-aa86-462dd61e31a3")));
IZoneIdentifier zoneIdentifier = (IZoneIdentifier)persistZoneId;
IPersistFile persisteFile = (IPersistFile)persistZoneId;
zoneIdentifier.SetId(URLZONE.URLZONE_UNTRUSTED);
persisteFile.Save(@"c:\temp\test.txt", false);
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)