FileSystemWatcher的下模拟的用户运行 [英] FileSystemWatcher running under impersonated user

查看:118
本文介绍了FileSystemWatcher的下模拟的用户运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在本地帐户下运行,但需要监控站点上的文件夹的C#WinForm应用程序。我使用稍微修改代码这里复制文件和工作正常。可类似的代码可与FileSystemWatcher的使用设置了模拟,以便我可以监视在站点上的文件夹?

I have an c# winform application that runs under a local account but needs to monitor folders on a domain. I am using slightly modified code from here to copy the files and that works fine. Can similar code be used with the FileSystemWatcher set up impersonation so I can monitor a folder on a domain?

推荐答案

是的,有一个很好的模拟类这里,包括这个类在你的项目不是简单地放置一个使用块内的FileSystemWatcher的像这样的:

Yes, there is a good impersonation class here, include this class in your project and than simply place your FileSystemWatcher within a using block like this:

using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) )
{
   ...

   <code that executes under the new context>

   ...
}

这篇关于FileSystemWatcher的下模拟的用户运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆