FilersystemWatcher在模拟用户下运行

Adm*_*eck 3 c# impersonation filesystemwatcher

我有一个c#winform应用程序,它在本地帐户下运行,但需要监视域上的文件夹.我使用稍微修改过的代码从这里复制文件,并且工作正常.可以使用类似的代码与FileSystemWatcher设置模拟,以便我可以监控域上的文件夹吗?

Dea*_*uga 6

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

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

   <code that executes under the new context>

   ...
}
Run Code Online (Sandbox Code Playgroud)