查阅资料的过程用了半天时间,首先想到的是看看系统有没有这样的命令,马上cmd键入help回车,看到一个cacls似乎看到了希望,简单看了一下帮助信息,然后搜索一下看看别人的经验,最后发现这个只是对文件的操作权限的修改,不能实现对文件夹设置权限。最后在http://www.codeproject.com/dotnet/NTSecurityNET.asp 发现了有一个用vc++写的类库,很方便使用,也比较简单,经测试有效。特写出来与大家分享。以下是我写的一个例子:
string accountName = System.Environment.UserName;
string system = System.Environment.MachineName;
accountName = "NETWORK SERVICE";
Microsoft.Win32.Security.WindowsUser wu = new Microsoft.Win32.Security.WindowsUser(accountName, system);
SecuredObject so = new SecuredObject();
so.ObjectName = @"d:\test";
so.ObjectType = SecuredObjectType.FileObject;
so.Permissions.SetAccess(wu, AccessRights.FileWriteUnsync, AceInheritanceFlags.ContainerInherit| AceInheritanceFlags.ObjectInherit);
string system = System.Environment.MachineName;
accountName = "NETWORK SERVICE";
Microsoft.Win32.Security.WindowsUser wu = new Microsoft.Win32.Security.WindowsUser(accountName, system);
SecuredObject so = new SecuredObject();
so.ObjectName = @"d:\test";
so.ObjectType = SecuredObjectType.FileObject;
so.Permissions.SetAccess(wu, AccessRights.FileWriteUnsync, AceInheritanceFlags.ContainerInherit| AceInheritanceFlags.ObjectInherit);