FilersystemWatcher在模拟用户下运行(FileSystemWatcher running under impersonated user)
我有一个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放置在如下的使用块中:
using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) ) { ... <code that executes under the new context> ... }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> ... }更多推荐
发布评论