如题,想写一个服务程序,监视一个文件夹,程序监视时禁止在文件夹中新建、修改、删除文件。
FileStreamWatcher 貌似无法实现,这个类的事件是在修改后才触发。
求思路。

解决方案 »

  1.   

    google shell hook copy file
      

  2.   

    Shell或者钩子应该可以
    命名管道
    var pipeServer = new NamedPipeServerStream(..);
    //添加自定义访问规则
    var acl = new System.IO.Pipes.PipeSecurity()
    {
       AccessRuleType =..,
       AccessRightType =..
    };
    acl.AddAccessRule(PipeAccessRule)
    pipeServer.SetAccessControl(acl);
    //应用规则后,模拟客户端运行
    pipeServer.RunAsClient()
    //客户端可以通过pipeClient.GetAccessControl()来判断权限
      

  3.   

    上面的思路是提供一个可控权限的文件服务端,要对用户操作进行限制
    在acl.AddAccessRule(PipeAccessRule)时
    可以new PipeAccessRule(IdentityReference, PipeAccessRights, AccessControlType)
    第一个参数可以关联一个WindowsIdentity
    不过我没试过,感觉可以